mirror of
https://github.com/ruby/ruby.git
synced 2026-11-08 01:20:26 +08:00
Preserve ensure handlers for unreachable labels
Ensure catch entries must remain active when dead code removal leaves unplaced range labels. Dropping them skips ensure clauses on exceptions. See https://github.com/ruby/ruby/pull/19513#issuecomment-6460531535.
This commit is contained in:
parent
e80cd771b3
commit
b1f8ac364d
Notes:
git
2026-10-28 07:16:01 +00:00
@ -3118,7 +3118,11 @@ iseq_set_exception_table(rb_iseq_t *iseq)
|
||||
int end = label_get_position((LABEL *)(ptr[2] & ~1));
|
||||
int cont = 0;
|
||||
int sp = 0;
|
||||
if (start < 0 || end < 0) continue;
|
||||
if (start < 0 || end < 0) {
|
||||
if ((ptr[0] & 0xffff) != CATCH_TYPE_ENSURE) continue;
|
||||
if (start < 0) start = 0;
|
||||
if (end < 0) end = 0;
|
||||
}
|
||||
if (ptr[4]) {
|
||||
LABEL *lobj = (LABEL *)(ptr[4] & ~1);
|
||||
cont = label_get_position(lobj);
|
||||
|
||||
@ -933,6 +933,20 @@ class TestISeq < Test::Unit::TestCase
|
||||
RUBY
|
||||
end
|
||||
|
||||
def test_short_circuited_return_in_ensure
|
||||
assert_in_out_err(["--parser=parse.y"], <<~'RUBY', ["ensure", "#<RuntimeError: boom>"], success: true)
|
||||
def m
|
||||
begin
|
||||
if false && (return if foo); end
|
||||
raise 'boom'
|
||||
ensure
|
||||
puts 'ensure'
|
||||
end
|
||||
end
|
||||
m rescue p $!
|
||||
RUBY
|
||||
end
|
||||
|
||||
def test_unreachable_syntax_error
|
||||
mesg = /Invalid break/
|
||||
assert_syntax_error("false and break", mesg)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user