[PRISM] Fix crash when multiple underscores

Fixes ruby/prism#2295.
This commit is contained in:
Peter Zhu 2024-01-29 16:35:54 -05:00
parent 4cf3c026de
commit bbb7ab906e
2 changed files with 9 additions and 2 deletions

View File

@ -2881,8 +2881,10 @@ pm_compile_destructured_param_locals(const pm_multi_target_node_t *node, st_tabl
const pm_node_t *left = node->lefts.nodes[index];
if (PM_NODE_TYPE_P(left, PM_REQUIRED_PARAMETER_NODE)) {
pm_insert_local_index(((const pm_required_parameter_node_t *) left)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
local_index++;
if (!PM_NODE_FLAG_P(left, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
pm_insert_local_index(((const pm_required_parameter_node_t *) left)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
local_index++;
}
} else {
RUBY_ASSERT(PM_NODE_TYPE_P(left, PM_MULTI_TARGET_NODE));
local_index = pm_compile_destructured_param_locals((const pm_multi_target_node_t *) left, index_lookup_table, local_table_for_iseq, scope_node, local_index);

View File

@ -2203,6 +2203,11 @@ end
assert_prism_eval("Object.tap { || }")
assert_prism_eval("[1].map { |num| num }")
assert_prism_eval("[1].map { |a; b| b = 2; a + b}")
# Test block parameters with multiple _
assert_prism_eval(<<~RUBY)
[[1, 2, 3, 4, 5, 6]].map { |(_, _, _, _, _, _)| _ }
RUBY
end
def test_FowardingParameterNode