From 853fd44745241398d182d2af3ebdea10640ebf2e Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Wed, 29 Nov 2023 14:58:26 -0500 Subject: [PATCH] [PRISM] Implement CallNodes with splat followed by args --- prism_compile.c | 12 ++++++++++-- test/ruby/test_compile_prism.rb | 13 ++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/prism_compile.c b/prism_compile.c index ca416547bb..79d5267667 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -1022,8 +1022,16 @@ pm_setup_args(pm_arguments_node_t *arguments_node, int *flags, struct rb_callinf } // If it's the final node else if (index == arguments_node_list.size - 1) { - ADD_INSN1(ret, &dummy_line_node, newarray, INT2FIX(post_splat_counter)); - ADD_INSN(ret, &dummy_line_node, concatarray); + if (post_splat_counter > 1) { + ADD_INSN1(ret, &dummy_line_node, newarray, INT2FIX(post_splat_counter)); + ADD_INSN1(ret, &dummy_line_node, splatarray, Qfalse); + ADD_INSN(ret, &dummy_line_node, concatarray); + } + else { + ADD_INSN1(ret, &dummy_line_node, newarray, INT2FIX(post_splat_counter)); + ADD_INSN(ret, &dummy_line_node, concatarray); + } + orig_argc = 1; } } } diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 7614abb628..e0db446fa7 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -935,12 +935,19 @@ module Prism # With different types of calling arguments assert_prism_eval(<<-CODE) - def self.prism_test_call_node(**); end - prism_test_call_node(b: 1, **{}) + def self.prism_test_call_node_double_splat(**); end + prism_test_call_node_double_splat(b: 1, **{}) CODE assert_prism_eval(<<-CODE) - prism_test_call_node(:b => 1) + prism_test_call_node_double_splat(:b => 1) CODE + + assert_prism_eval(<<-CODE) + def self.prism_test_call_node_splat(*); end + prism_test_call_node_splat(*[], 1) + CODE + + assert_prism_eval("prism_test_call_node_splat(*[], 1, 2)") end def test_CallAndWriteNode