From 667a0f9f928be843a0810f2c61b633be1f8cd46a Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sun, 22 Dec 2024 20:46:50 -0800 Subject: [PATCH] Revert "[Bug #20965] Define `it` like an ordinary argument" (#12418) Revert "[Bug #20965] Define `it` like an ordinary argument (#12398)" Reverts ruby/ruby#12398 as per https://bugs.ruby-lang.org/issues/20970#note-6 and https://bugs.ruby-lang.org/issues/20965#note-7. We need more time to design the intended behavior, and it's too late for Ruby 3.4. --- defs/id.def | 1 - parse.y | 2 +- prism_compile.c | 2 +- test/ruby/test_syntax.rb | 7 ++----- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/defs/id.def b/defs/id.def index 6d7217f155..5e2da592ef 100644 --- a/defs/id.def +++ b/defs/id.def @@ -63,7 +63,6 @@ firstline, predefined = __LINE__+1, %[\ pack buffer include? - it _ UScore diff --git a/parse.y b/parse.y index ee85f5f8a7..cbce831c5b 100644 --- a/parse.y +++ b/parse.y @@ -13060,7 +13060,7 @@ gettable(struct parser_params *p, ID id, const YYLTYPE *loc) return 0; } if (!p->it_id) { - p->it_id = idIt; + p->it_id = internal_id(p); vtable_add(p->lvtbl->args, p->it_id); } NODE *node = NEW_DVAR(p->it_id, loc); diff --git a/prism_compile.c b/prism_compile.c index 30e7c76255..bb3d91ffde 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -5960,7 +5960,7 @@ pm_compile_scope_node(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_nod } if (scope_node->parameters != NULL && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) { - ID local = idIt; + ID local = rb_make_temporary_id(local_index); local_table_for_iseq->ids[local_index++] = local; } diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 1a5c538050..edf5886a53 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1930,15 +1930,12 @@ eom 1.times do [ assert_equal(0, it), - assert_equal([0], eval('[:a].map{it}')), - assert_equal(0, eval('it')), + assert_equal([:a], eval('[:a].map{it}')), + assert_raise(NameError) {eval('it')}, ] end assert_valid_syntax('proc {def foo(_);end;it}') assert_syntax_error('p { [it **2] }', /unexpected \*\*/) - - b = proc {it; binding}.call - assert_include(b.local_variables, :it) end def test_value_expr_in_condition