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

simple rescue+while+break should not use throw #4507

Merged
merged 1 commit into from
May 21, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5409,12 +5409,14 @@ add_ensure_range(rb_iseq_t *iseq, struct ensure_range *erange,
static bool
can_add_ensure_iseq(const rb_iseq_t *iseq)
{
if (ISEQ_COMPILE_DATA(iseq)->in_rescue && ISEQ_COMPILE_DATA(iseq)->ensure_node_stack) {
return false;
}
else {
return true;
struct iseq_compile_data_ensure_node_stack *e;
if (ISEQ_COMPILE_DATA(iseq)->in_rescue && (e = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack) != NULL) {
while (e) {
if (e->ensure_node) return false;
e = e->prev;
}
}
return true;
}

static void
Expand Down
11 changes: 11 additions & 0 deletions test/ruby/test_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ def test_exception_in_ensure_with_next
end
end
end

iseq = RubyVM::InstructionSequence.compile(<<-RUBY)
begin
while true
break
end
rescue
end
RUBY

assert_equal false, iseq.to_a[13].any?{|(e,_)| e == :throw}
end

def test_exception_in_ensure_with_redo
Expand Down