From 6e88b72d7bdac5d959d525df6e3804f4c1eaf9ce Mon Sep 17 00:00:00 2001 From: Adam Hess Date: Mon, 16 Oct 2023 05:22:07 -0700 Subject: [PATCH] [PRISM] prevent underflow on popped splatarray (#8657) prevent underflow on popped splatarray This only emits the splat array node when not popped --- prism_compile.c | 6 +++--- test/ruby/test_compile_prism.rb | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/prism_compile.c b/prism_compile.c index 3be1997eb7..a0312625fa 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -2397,9 +2397,9 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, PM_COMPILE(splat_node->expression); } - ADD_INSN1(ret, &dummy_line_node, splatarray, Qtrue); - - PM_POP_IF_POPPED; + if (!popped) { + ADD_INSN1(ret, &dummy_line_node, splatarray, Qtrue); + } return; } case PM_STATEMENTS_NODE: { diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index f94bd603ca..763ac044ba 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -325,6 +325,10 @@ module Prism test_prism_eval("[ Prism: [:b, :c]]") end + def test_SplatNode + test_prism_eval("*b = []") + end + ############################################################################ # Jumps # ############################################################################