Skip to content

Commit

Permalink
[PRISM] Fixed rest in MultiTargetNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jemmaissroff committed Dec 11, 2023
1 parent aaeccc2 commit 5c8e191
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion prism_compile.c
Expand Up @@ -3711,9 +3711,12 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
}
case PM_MULTI_TARGET_NODE: {
pm_multi_target_node_t *cast = (pm_multi_target_node_t *) node;
bool has_rest_expression = (cast->rest &&
PM_NODE_TYPE_P(cast->rest, PM_SPLAT_NODE) &&
(((pm_splat_node_t *)cast->rest)->expression));

if (cast->lefts.size) {
int flag = (int) (bool) cast->rights.size;
int flag = (int) (bool) cast->rights.size || has_rest_expression;
ADD_INSN2(ret, &dummy_line_node, expandarray, INT2FIX(cast->lefts.size), INT2FIX(flag));
for (size_t index = 0; index < cast->lefts.size; index++) {
PM_COMPILE_NOT_POPPED(cast->lefts.nodes[index]);
Expand All @@ -3726,6 +3729,11 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
PM_COMPILE_NOT_POPPED(cast->rights.nodes[index]);
}
}

if (has_rest_expression) {
pm_node_t *expression = ((pm_splat_node_t *)cast->rest)->expression;
PM_COMPILE_NOT_POPPED(expression);
}
return;
}
case PM_MULTI_WRITE_NODE: {
Expand Down
3 changes: 3 additions & 0 deletions test/ruby/test_compile_prism.rb
Expand Up @@ -502,6 +502,9 @@ def test_MultiTargetNode
assert_prism_eval("a, (b, c) = [1, 2, 3]; b")
assert_prism_eval("a, (b, c) = [1, 2, 3]; c")
assert_prism_eval("a, (b, c) = [1, [2, 3]]; c")
assert_prism_eval("a, (b, *c) = [1, [2, 3]]; c")
assert_prism_eval("a, (b, *c) = 1, [2, 3]; c")
assert_prism_eval("a, (b, *) = 1, [2, 3]; b")
assert_prism_eval("(a, (b, c, d, e), f, g), h = [1, [2, 3]], 4, 5, [6, 7]; c")
end

Expand Down

0 comments on commit 5c8e191

Please sign in to comment.