Skip to content

Commit c47a805

Browse files
committed
Add a test case for complex argument forward reference
Using `eval` it's possible to reference a later argument, and this requires careful initialization of the stack.
1 parent 1596853 commit c47a805

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/ruby/test_call.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ def self.f(*a); a end
123123
assert_equal([1, 2, {kw: 3}], f(*a, kw: 3))
124124
end
125125

126+
def test_forward_argument_init
127+
o = Object.new
128+
def o.simple_forward_argument_init(a=eval('b'), b=1)
129+
[a, b]
130+
end
131+
132+
def o.complex_forward_argument_init(a=eval('b'), b=eval('kw'), kw: eval('kw2'), kw2: 3)
133+
[a, b, kw, kw2]
134+
end
135+
136+
def o.keyword_forward_argument_init(a: eval('b'), b: eval('kw'), kw: eval('kw2'), kw2: 3)
137+
[a, b, kw, kw2]
138+
end
139+
140+
assert_equal [nil, 1], o.simple_forward_argument_init
141+
assert_equal [nil, nil, 3, 3], o.complex_forward_argument_init
142+
assert_equal [nil, nil, 3, 3], o.keyword_forward_argument_init
143+
end
144+
126145
def test_call_bmethod_proc
127146
pr = proc{|sym| sym}
128147
define_singleton_method(:a, &pr)

0 commit comments

Comments
 (0)