Skip to content

Commit da884f4

Browse files
pvcresincodex
authored andcommitted
Support forwarded arguments in super and nested blocks
Co-authored-by: OpenAI Codex <codex@openai.com>
1 parent 80768af commit da884f4

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

lib/typeprof/core/ast/call.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def install0(genv)
132132
if @block_body
133133
block_body = @block_body # kinda type annotationty
134134
block_tbl = @block_tbl || raise
135+
block_body.lenv.forward_args = @lenv.forward_args
135136
@lenv.locals.each {|var, vtx| block_body.lenv.locals[var] = vtx }
136137
block_tbl.each {|var| block_body.lenv.locals[var] = Source.new(genv.nil_type) }
137138
block_body.lenv.locals[:"*self"] = block_body.lenv.cref.get_self(genv)
@@ -314,9 +315,9 @@ def initialize(raw_node, lenv)
314315

315316
class ForwardingSuperNode < CallBaseNode
316317
def initialize(raw_node, lenv)
317-
raw_args = nil # TODO: forward args properly
318+
raw_args = nil
318319
raw_block = raw_node.block
319-
super(raw_node, nil, :"*super", nil, raw_args, nil, raw_block, lenv)
320+
super(raw_node, nil, :"*super", nil, raw_args, nil, raw_block, lenv, forwarding_arguments: true)
320321
end
321322
end
322323

scenario/args/forwarding_arguments.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,20 @@ class Object
3636
def foo: (*Integer, **Integer) -> [Array[Integer], { x: Integer, y: Integer }]
3737
def bar: (*Integer, **Integer) -> [Array[Integer], { x: Integer, y: Integer }]
3838
end
39+
40+
## update
41+
def foo(...)
42+
1.times { bar(...) }
43+
end
44+
45+
def bar(*a, **b)
46+
[a, b]
47+
end
48+
49+
foo(1, x: 4, y: 5)
50+
51+
## assert
52+
class Object
53+
def foo: (*Integer, **Integer) -> Integer
54+
def bar: (*Integer, **Integer) -> [Array[Integer], { x: Integer, y: Integer }]
55+
end

scenario/misc/super.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,26 @@ def [](key)
3636
class StringifyKeyHash < Hash
3737
def []: (untyped) -> untyped
3838
end
39+
40+
## update
41+
class SuperBase
42+
def foo(*a, **b)
43+
[a, b]
44+
end
45+
end
46+
47+
class SuperChild < SuperBase
48+
def foo(...)
49+
super(...)
50+
end
51+
end
52+
53+
SuperChild.new.foo(1, x: 4, y: 5)
54+
55+
## assert
56+
class SuperBase
57+
def foo: (*Integer, **Integer) -> [Array[Integer], { x: Integer, y: Integer }]
58+
end
59+
class SuperChild < SuperBase
60+
def foo: (*Integer, **Integer) -> [Array[Integer], { x: Integer, y: Integer }]
61+
end

0 commit comments

Comments
 (0)