Skip to content

Commit

Permalink
[PRISM] Fix splat inside of aset
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Jan 11, 2024
1 parent f2149dc commit 45dd8ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion prism_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2645,9 +2645,17 @@ pm_compile_call(rb_iseq_t *iseq, const pm_call_node_t *call_node, LINK_ANCHOR *c
}

if (pm_node->flags & PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) {
if (!popped) {
if (flags & VM_CALL_ARGS_SPLAT) {
ADD_INSN(ret, &dummy_line_node, dup);
ADD_INSN1(ret, &dummy_line_node, putobject, INT2FIX(-1));
ADD_SEND_WITH_FLAG(ret, &dummy_line_node, idAREF, INT2FIX(1), INT2FIX(0));
ADD_INSN1(ret, &dummy_line_node, setn, INT2FIX(orig_argc + 2));
ADD_INSN (ret, &dummy_line_node, pop);
}
else if (!popped) {
ADD_INSN1(ret, &dummy_line_node, setn, INT2FIX(orig_argc + 1));
}

ADD_SEND_R(ret, &dummy_line_node, method_id, INT2FIX(orig_argc), block_iseq, INT2FIX(flags), kw_arg);
PM_POP_UNLESS_POPPED;
}
Expand Down
7 changes: 7 additions & 0 deletions test/ruby/test_compile_prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,13 @@ def foo.[]=(k,v); 42; end
foo.[]=(1,2)
CODE

# With splat inside of []=
assert_prism_eval(<<~RUBY)
obj = Object.new
def obj.[]=(a, b); 10; end
obj[*[1]] = 3
RUBY

assert_prism_eval(<<-CODE)
def self.prism_opt_var_trail_hash(a = nil, *b, c, **d); end
prism_opt_var_trail_hash("a")
Expand Down

0 comments on commit 45dd8ed

Please sign in to comment.