From 2a8d9c59ff151e8e2274e5f788745e070111b8ab Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Fri, 1 Dec 2023 13:00:20 -0500 Subject: [PATCH] [PRISM] Account for RescueNodes with no statements We need a PUTNIL if a RescueNode has no statements. --- prism_compile.c | 5 +++++ test/ruby/test_compile_prism.rb | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/prism_compile.c b/prism_compile.c index 04cdb89ce4..1b55396b0b 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -3658,9 +3658,14 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, ADD_GETLOCAL(ret, &dummy_line_node, LVAR_ERRINFO, 0); PM_COMPILE((pm_node_t *)rescue_node->reference); } + if (rescue_node->statements) { PM_COMPILE((pm_node_t *)rescue_node->statements); } + else { + PM_PUTNIL; + } + ADD_INSN(ret, &dummy_line_node, leave); ADD_LABEL(ret, rescue_end); diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 2786e2052d..f9f42ce7ec 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -792,6 +792,12 @@ module Prism rescue StandardError => e end CODE + assert_prism_eval(<<~CODE) + begin + raise StandardError + rescue StandardError => e + end + CODE assert_prism_eval(<<~CODE) begin 1