mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[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
This commit is contained in:
parent
04d43e1870
commit
265059603c
2 changed files with 24 additions and 0 deletions
|
@ -6767,6 +6767,17 @@ pm_compile_scope_node(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_nod
|
|||
body->param.flags.has_lead = true;
|
||||
}
|
||||
|
||||
if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
|
||||
const uint8_t param_name[] = { 'i', 't' };
|
||||
pm_constant_id_t constant_id = pm_constant_pool_find(&scope_node->parser->constant_pool, param_name, 2);
|
||||
RUBY_ASSERT(constant_id && "parser should fill in `it` parameter");
|
||||
pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
|
||||
|
||||
local_index++;
|
||||
body->param.lead_num = 1;
|
||||
body->param.flags.has_lead = true;
|
||||
}
|
||||
|
||||
//********END OF STEP 3**********
|
||||
|
||||
//********STEP 4**********
|
||||
|
|
|
@ -1957,6 +1957,19 @@ eom
|
|||
assert_equal(/9/, eval('9.then { /#{it}/o }'))
|
||||
end
|
||||
|
||||
def test_it_with_splat_super_method
|
||||
bug21256 = '[ruby-core:121592] [Bug #21256]'
|
||||
|
||||
a = Class.new do
|
||||
define_method(:foo) { it }
|
||||
end
|
||||
b = Class.new(a) do
|
||||
def foo(*args) = super
|
||||
end
|
||||
|
||||
assert_equal(1, b.new.foo(1), bug21256)
|
||||
end
|
||||
|
||||
def test_value_expr_in_condition
|
||||
mesg = /void value expression/
|
||||
assert_syntax_error("tap {a = (true ? next : break)}", mesg)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue