Skip to content

Commit ab99ce9

Browse files
committed
[PRISM] Insert concatarray for index targets with splat
1 parent e5f8585 commit ab99ce9

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

prism_compile.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ pm_setup_args(pm_arguments_node_t *arguments_node, int *flags, struct rb_callinf
11471147
}
11481148
else {
11491149
// If this is not the first splat array seen and it is also
1150-
// the last parameter, we don't want splayarray to dup it
1150+
// the last parameter, we don't want splatarray to dup it
11511151
// and we need to concat the array.
11521152
//
11531153
// foo(a, *b, *c)
@@ -3110,7 +3110,7 @@ pm_compile_target_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *cons
31103110

31113111
if (cast->block != NULL) {
31123112
flags |= VM_CALL_ARGS_BLOCKARG;
3113-
if (cast->block != NULL) pm_compile_node(iseq, cast->block, writes, src, false, scope_node);
3113+
if (cast->block != NULL) pm_compile_node(iseq, cast->block, parents, src, false, scope_node);
31143114
}
31153115

31163116
if (state != NULL) {
@@ -3127,7 +3127,18 @@ pm_compile_target_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *cons
31273127
}
31283128
}
31293129

3130-
ADD_SEND_R(writes, &dummy_line_node, idASET, INT2NUM(argc + 1), NULL, INT2FIX(flags), kwargs);
3130+
// The argc that we're going to pass to the send instruction is the
3131+
// number of arguments + 1 for the value being written. If there's a
3132+
// splat, then we need to insert newarray and concatarray instructions
3133+
// after the arguments have been written.
3134+
int ci_argc = argc + 1;
3135+
if (flags & VM_CALL_ARGS_SPLAT) {
3136+
ci_argc--;
3137+
ADD_INSN1(writes, &dummy_line_node, newarray, INT2FIX(1));
3138+
ADD_INSN(writes, &dummy_line_node, concatarray);
3139+
}
3140+
3141+
ADD_SEND_R(writes, &dummy_line_node, idASET, INT2NUM(ci_argc), NULL, INT2FIX(flags), kwargs);
31313142
ADD_INSN(writes, &dummy_line_node, pop);
31323143

31333144
if (state != NULL) {

0 commit comments

Comments
 (0)