From 5c8e1911ca19bc3d346db5ae6314cc8957e9339a Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Mon, 11 Dec 2023 14:46:24 -0500 Subject: [PATCH] [PRISM] Fixed rest in MultiTargetNodes --- prism_compile.c | 10 +++++++++- test/ruby/test_compile_prism.rb | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/prism_compile.c b/prism_compile.c index 251e4b398e..708a2baff6 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -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]); @@ -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: { diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index e501efa6c9..dde51b3cb2 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -502,6 +502,9 @@ module Prism 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