Skip to content

Commit

Permalink
[PRISM] Fix else with rescue
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 authored and kddnewton committed Jan 31, 2024
1 parent 95c9711 commit cb98b01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion prism_compile.c
Expand Up @@ -3583,12 +3583,13 @@ pm_compile_rescue(rb_iseq_t *iseq, pm_begin_node_t *begin_node, LINK_ANCHOR *con
}
ISEQ_COMPILE_DATA(iseq)->in_rescue = prev_in_rescue;

ADD_LABEL(ret, lend);

if (begin_node->else_clause) {
PM_POP_UNLESS_POPPED;
PM_COMPILE((pm_node_t *)begin_node->else_clause);
}

ADD_LABEL(ret, lend);
PM_NOP;
ADD_LABEL(ret, lcont);

Expand Down
17 changes: 17 additions & 0 deletions test/ruby/test_compile_prism.rb
Expand Up @@ -1395,6 +1395,23 @@ def test_RescueNode
end
end
CODE

# Test RescueNode with ElseNode
assert_prism_eval(<<~RUBY)
calls = []
begin
begin
rescue RuntimeError
calls << 1
else
calls << 2
raise RuntimeError
end
rescue RuntimeError
end
calls
RUBY
end

def test_RescueModifierNode
Expand Down

0 comments on commit cb98b01

Please sign in to comment.