diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2026-01-02 10:47:55 +0100 |
|---|---|---|
| committer | Jean Boussier <jean.boussier@gmail.com> | 2026-01-02 16:59:00 +0100 |
| commit | c47a8052f6ecd3fb981416d6bfd918590572bb37 (patch) | |
| tree | afb8859836889e4188feab73f27a47962616e48a | |
| parent | 1596853428393136ee9964ad4c11b0120ed648d1 (diff) | |
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.
| -rw-r--r-- | test/ruby/test_call.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_call.rb b/test/ruby/test_call.rb index 1b30ed34d8..dd1936c4e2 100644 --- a/test/ruby/test_call.rb +++ b/test/ruby/test_call.rb @@ -123,6 +123,25 @@ class TestCall < Test::Unit::TestCase assert_equal([1, 2, {kw: 3}], f(*a, kw: 3)) end + def test_forward_argument_init + o = Object.new + def o.simple_forward_argument_init(a=eval('b'), b=1) + [a, b] + end + + def o.complex_forward_argument_init(a=eval('b'), b=eval('kw'), kw: eval('kw2'), kw2: 3) + [a, b, kw, kw2] + end + + def o.keyword_forward_argument_init(a: eval('b'), b: eval('kw'), kw: eval('kw2'), kw2: 3) + [a, b, kw, kw2] + end + + assert_equal [nil, 1], o.simple_forward_argument_init + assert_equal [nil, nil, 3, 3], o.complex_forward_argument_init + assert_equal [nil, nil, 3, 3], o.keyword_forward_argument_init + end + def test_call_bmethod_proc pr = proc{|sym| sym} define_singleton_method(:a, &pr) |
