diff --git a/src/vm.c b/src/vm.c index 8075a6e6e..12ee4aa9e 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1721,7 +1721,7 @@ RETRY_TRY_BLOCK: if (irep->clen > 0 && (ch = catch_handler_find(irep, ci->pc, MRB_CATCH_FILTER_ENSURE))) { /* avoiding a jump from a catch handler into the same handler */ - if (a < mrb_irep_catch_handler_unpack(ch->begin) || a >= mrb_irep_catch_handler_unpack(ch->end)) { + if (a < mrb_irep_catch_handler_unpack(ch->begin) || a > mrb_irep_catch_handler_unpack(ch->end)) { THROW_TAGGED_BREAK(mrb, RBREAK_TAG_JUMP, mrb->c->ci, mrb_fixnum_value(a)); } } diff --git a/test/t/syntax.rb b/test/t/syntax.rb index dedbbd1c2..f26bc1c52 100644 --- a/test/t/syntax.rb +++ b/test/t/syntax.rb @@ -71,6 +71,63 @@ assert('break', '11.5.2.4.3') do end end assert_equal [1,2,3,4], a + + a = [] + begin + while true + a.push 1 + break + a.push "NG" + end + ensure + a.push 2 + end + assert_equal [1, 2], a + + a = [] + begin + while true + a.push 1 + break + end + a.push 2 + ensure + a.push 3 + end + assert_equal [1, 2, 3], a + + a = [] + begin + while true + begin + a.push 1 + break + ensure + a.push 2 + end + a.push "NG" + end + ensure + a.push 3 + end + assert_equal [1, 2, 3], a + + a = [] + begin + while true + begin + a.push 1 + break + ensure + a.push 2 + end + a.push "NG" + end + a.push 3 + ensure + a.push 4 + end + assert_equal [1, 2, 3, 4], a end assert('redo', '11.5.2.4.5') do