From 1838dbf6e7f9335e5ad23d9856bd014d18446f07 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 22 Jan 2024 15:13:33 -0500 Subject: [PATCH] [PRISM] Fix splat and block in aset --- prism_compile.c | 4 ++++ test/ruby/test_compile_prism.rb | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/prism_compile.c b/prism_compile.c index 8c4f0fed0a..e5ba24115d 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -2713,6 +2713,10 @@ 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 (flags & VM_CALL_ARGS_BLOCKARG) { ADD_INSN1(ret, &dummy_line_node, topn, INT2FIX(1)); + if (flags & VM_CALL_ARGS_SPLAT) { + 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 + 3)); PM_POP; } diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 7705959f4c..fd5787e467 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -1771,6 +1771,15 @@ end obj[&p] = 4 RUBY + # Test splat and block inside of []= + assert_prism_eval(<<~RUBY) + obj = Object.new + def obj.[]=(a, b); end + + p = proc {} + obj[*[1], &p] = 4 + RUBY + assert_prism_eval(<<-CODE) def self.prism_opt_var_trail_hash(a = nil, *b, c, **d); end prism_opt_var_trail_hash("a")