diff --git a/prism_compile.c b/prism_compile.c index ed5f1367ed..9594be7065 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -5582,7 +5582,6 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, } if (requireds_list) { - int number_of_anonymous_locals = 0; for (size_t i = 0; i < requireds_list->size; i++) { // For each MultiTargetNode, we're going to have one // additional anonymous local not represented in the locals table @@ -5592,19 +5591,11 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, table_size++; } else if (PM_NODE_TYPE_P(required, PM_REQUIRED_PARAMETER_NODE)) { - if (pm_constant_id_lookup(scope_node, ((pm_required_parameter_node_t *)required)->name) == rb_intern("_")) { - number_of_anonymous_locals++; + if (PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) { + table_size++; } } } - - // For each anonymous local we also want to increase the size - // of the locals table. Prism's locals table accounts for all - // anonymous locals as 1, so we need to increase the table size - // by the number of anonymous locals - 1 - if (number_of_anonymous_locals > 1) { - table_size += (number_of_anonymous_locals - 1); - } } if (posts_list) { @@ -5686,7 +5677,9 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, case PM_REQUIRED_PARAMETER_NODE: { pm_required_parameter_node_t * param = (pm_required_parameter_node_t *)required; - pm_insert_local_index(param->name, local_index, index_lookup_table, local_table_for_iseq, scope_node); + if (!PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) { + pm_insert_local_index(param->name, local_index, index_lookup_table, local_table_for_iseq, scope_node); + } break; } default: { diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 99f932a238..835b3b819b 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -1299,6 +1299,10 @@ module Prism CODE end + def test_repeated_method_params + assert_prism_eval("def self.foo(_a, _a); _a; end; foo(1, 2)") + end + def test_method_parameters assert_prism_eval(<<-CODE) def self.prism_test_method_parameters(a, b=1, *c, d:, e: 2, **f, &g)