Skip to content

Commit 2650596

Browse files
Earlopaintenderlove
authored andcommitted
[Bug #21256] Fix it parameter when splatting and define_method is used
It was failing to set the leads, like numblocks do, causing the result to be wrapped in an array
1 parent 04d43e1 commit 2650596

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

prism_compile.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6767,6 +6767,17 @@ pm_compile_scope_node(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_nod
67676767
body->param.flags.has_lead = true;
67686768
}
67696769

6770+
if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6771+
const uint8_t param_name[] = { 'i', 't' };
6772+
pm_constant_id_t constant_id = pm_constant_pool_find(&scope_node->parser->constant_pool, param_name, 2);
6773+
RUBY_ASSERT(constant_id && "parser should fill in `it` parameter");
6774+
pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6775+
6776+
local_index++;
6777+
body->param.lead_num = 1;
6778+
body->param.flags.has_lead = true;
6779+
}
6780+
67706781
//********END OF STEP 3**********
67716782

67726783
//********STEP 4**********

test/ruby/test_syntax.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,19 @@ def test_it
19571957
assert_equal(/9/, eval('9.then { /#{it}/o }'))
19581958
end
19591959

1960+
def test_it_with_splat_super_method
1961+
bug21256 = '[ruby-core:121592] [Bug #21256]'
1962+
1963+
a = Class.new do
1964+
define_method(:foo) { it }
1965+
end
1966+
b = Class.new(a) do
1967+
def foo(*args) = super
1968+
end
1969+
1970+
assert_equal(1, b.new.foo(1), bug21256)
1971+
end
1972+
19601973
def test_value_expr_in_condition
19611974
mesg = /void value expression/
19621975
assert_syntax_error("tap {a = (true ? next : break)}", mesg)

0 commit comments

Comments
 (0)