diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-01-22 11:36:55 -0500 |
|---|---|---|
| committer | Kevin Newton <kddnewton@gmail.com> | 2024-01-22 12:55:06 -0500 |
| commit | ab99ce910ce9a7aeb0b8a3224a1ed1e3e5faf71f (patch) | |
| tree | a8bfc4049027450a1af562b7e65cc6eb4b7a678f | |
| parent | e5f8585a2999bff59e8b79605db7868bf702f84b (diff) | |
[PRISM] Insert concatarray for index targets with splat
| -rw-r--r-- | prism_compile.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/prism_compile.c b/prism_compile.c index 8f86b92975..40d2eb9806 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -1147,7 +1147,7 @@ pm_setup_args(pm_arguments_node_t *arguments_node, int *flags, struct rb_callinf } else { // If this is not the first splat array seen and it is also - // the last parameter, we don't want splayarray to dup it + // the last parameter, we don't want splatarray to dup it // and we need to concat the array. // // foo(a, *b, *c) @@ -3110,7 +3110,7 @@ pm_compile_target_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *cons if (cast->block != NULL) { flags |= VM_CALL_ARGS_BLOCKARG; - if (cast->block != NULL) pm_compile_node(iseq, cast->block, writes, src, false, scope_node); + if (cast->block != NULL) pm_compile_node(iseq, cast->block, parents, src, false, scope_node); } if (state != NULL) { @@ -3127,7 +3127,18 @@ pm_compile_target_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *cons } } - ADD_SEND_R(writes, &dummy_line_node, idASET, INT2NUM(argc + 1), NULL, INT2FIX(flags), kwargs); + // The argc that we're going to pass to the send instruction is the + // number of arguments + 1 for the value being written. If there's a + // splat, then we need to insert newarray and concatarray instructions + // after the arguments have been written. + int ci_argc = argc + 1; + if (flags & VM_CALL_ARGS_SPLAT) { + ci_argc--; + ADD_INSN1(writes, &dummy_line_node, newarray, INT2FIX(1)); + ADD_INSN(writes, &dummy_line_node, concatarray); + } + + ADD_SEND_R(writes, &dummy_line_node, idASET, INT2NUM(ci_argc), NULL, INT2FIX(flags), kwargs); ADD_INSN(writes, &dummy_line_node, pop); if (state != NULL) { |
