[PRISM] Support repeated required parameter names.
Fixes: https://github.com/ruby/prism/issues/2062 This patch only fixes positional parameters, we still need to fix the other cases spelled out in test/prism/fixtures/repeat_parameters.txt
This commit is contained in:
parent
72be786017
commit
f2149dc094
@ -5582,7 +5582,6 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (requireds_list) {
|
if (requireds_list) {
|
||||||
int number_of_anonymous_locals = 0;
|
|
||||||
for (size_t i = 0; i < requireds_list->size; i++) {
|
for (size_t i = 0; i < requireds_list->size; i++) {
|
||||||
// For each MultiTargetNode, we're going to have one
|
// For each MultiTargetNode, we're going to have one
|
||||||
// additional anonymous local not represented in the locals table
|
// 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++;
|
table_size++;
|
||||||
}
|
}
|
||||||
else if (PM_NODE_TYPE_P(required, PM_REQUIRED_PARAMETER_NODE)) {
|
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("_")) {
|
if (PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
|
||||||
number_of_anonymous_locals++;
|
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) {
|
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: {
|
case PM_REQUIRED_PARAMETER_NODE: {
|
||||||
pm_required_parameter_node_t * param = (pm_required_parameter_node_t *)required;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -1299,6 +1299,10 @@ module Prism
|
|||||||
CODE
|
CODE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_repeated_method_params
|
||||||
|
assert_prism_eval("def self.foo(_a, _a); _a; end; foo(1, 2)")
|
||||||
|
end
|
||||||
|
|
||||||
def test_method_parameters
|
def test_method_parameters
|
||||||
assert_prism_eval(<<-CODE)
|
assert_prism_eval(<<-CODE)
|
||||||
def self.prism_test_method_parameters(a, b=1, *c, d:, e: 2, **f, &g)
|
def self.prism_test_method_parameters(a, b=1, *c, d:, e: 2, **f, &g)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user