Skip to content

Commit

Permalink
[PRISM] Account for RescueNodes with no statements
Browse files Browse the repository at this point in the history
We need a PUTNIL if a RescueNode has no statements.
  • Loading branch information
jemmaissroff committed Dec 1, 2023
1 parent d6584a0 commit 2a8d9c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions prism_compile.c
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions test/ruby/test_compile_prism.rb
Expand Up @@ -792,6 +792,12 @@ def test_RescueNode
rescue StandardError => e
end
CODE
assert_prism_eval(<<~CODE)
begin
raise StandardError
rescue StandardError => e
end
CODE
assert_prism_eval(<<~CODE)
begin
1
Expand Down

0 comments on commit 2a8d9c5

Please sign in to comment.