Skip to content

Commit 4f4b4e3

Browse files
kddnewtonEarlopain
andcommitted
Fill in lead num for blocks with it
Fixes [Bug #21256] Co-Authored-By: Earlopain <[email protected]>
1 parent c5feae9 commit 4f4b4e3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

prism_compile.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6740,6 +6740,12 @@ pm_compile_scope_node(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_nod
67406740
body->param.flags.has_lead = true;
67416741
}
67426742

6743+
// Fill in the anonymous `it` parameter, if it exists
6744+
if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6745+
body->param.lead_num = 1;
6746+
body->param.flags.has_lead = true;
6747+
}
6748+
67436749
//********END OF STEP 3**********
67446750

67456751
//********STEP 4**********

test/ruby/test_syntax.rb

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

2007+
def test_it_with_splat_super_method
2008+
bug21256 = '[ruby-core:121592] [Bug #21256]'
2009+
2010+
a = Class.new do
2011+
define_method(:foo) { it }
2012+
end
2013+
b = Class.new(a) do
2014+
def foo(*args) = super
2015+
end
2016+
2017+
assert_equal(1, b.new.foo(1), bug21256)
2018+
end
2019+
20072020
def test_value_expr_in_condition
20082021
mesg = /void value expression/
20092022
assert_syntax_error("tap {a = (true ? next : break)}", mesg)

0 commit comments

Comments
 (0)