[PRISM] Fix anonymous splat nodes

Fixes ruby/prism#2257.
This commit is contained in:
Peter Zhu 2024-01-23 16:13:18 -05:00
parent 996776e936
commit 909a710a69
2 changed files with 14 additions and 1 deletions

View File

@ -59,6 +59,7 @@
#define PM_SPECIAL_CONSTANT_FLAG ((pm_constant_id_t)(1 << 31))
#define PM_CONSTANT_AND ((pm_constant_id_t)(idAnd | PM_SPECIAL_CONSTANT_FLAG))
#define PM_CONSTANT_MULT ((pm_constant_id_t)(idMULT | PM_SPECIAL_CONSTANT_FLAG))
rb_iseq_t *
pm_iseq_new_with_opt(pm_scope_node_t *scope_node, pm_parser_t *parser, VALUE name, VALUE path, VALUE realpath,
@ -1125,6 +1126,10 @@ pm_setup_args(pm_arguments_node_t *arguments_node, int *flags, struct rb_callinf
if (splat_node->expression) {
PM_COMPILE_NOT_POPPED(splat_node->expression);
}
else {
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
ADD_GETLOCAL(ret, &dummy_line_node, index.index, index.level);
}
bool first_splat = !has_splat;
@ -6431,7 +6436,8 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
else {
// def foo(a, (b, *c, d), e = 1, *, g, (h, *i, j), k:, l: 1, **m, &n)
// ^
local_table_for_iseq->ids[local_index] = idMULT;
local_table_for_iseq->ids[local_index] = PM_CONSTANT_MULT;
st_insert(index_lookup_table, PM_CONSTANT_MULT, local_index);
}
local_index++;
}

View File

@ -849,6 +849,13 @@ module Prism
assert_prism_eval("*b, c = [1, 2, 3]; c")
assert_prism_eval("a, *, c = [1, 2, 3]; a")
assert_prism_eval("a, *, c = [1, 2, 3]; c")
# Test anonymous splat node
assert_prism_eval(<<~RUBY)
def self.bar(*) = Array(*)
bar([1, 2, 3])
RUBY
end
############################################################################