Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PRISM] Fix next inside rescue #9703

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions prism_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -6131,7 +6131,18 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
// If we have statements to execute, we'll compile them here. Otherwise
// we'll push nil onto the stack.
if (cast->statements) {

// We'll temporarily remove the end_label location from the iseq
// when compiling the statements so that next/redo statements
// inside the body will throw to the correct place instead of
// jumping straight to the end of this iseq
LABEL *prev_end = ISEQ_COMPILE_DATA(iseq)->end_label;
ISEQ_COMPILE_DATA(iseq)->end_label = NULL;

PM_COMPILE((pm_node_t *) cast->statements);

// Now restore the end_label
ISEQ_COMPILE_DATA(iseq)->end_label = prev_end;
} else {
PM_PUTNIL;
}
Expand Down
9 changes: 9 additions & 0 deletions test/ruby/test_compile_prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,15 @@ def test_NextNode
next
end
CODE

assert_prism_eval(<<~CODE)
[].each do
begin
rescue
next
end
end
CODE
end

def test_RedoNode
Expand Down