aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/ruby/test_enum.rb21
-rw-r--r--vm.c8
2 files changed, 26 insertions, 3 deletions
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb
index f774c4260b..09f978502a 100644
--- a/test/ruby/test_enum.rb
+++ b/test/ruby/test_enum.rb
@@ -53,7 +53,8 @@ class TestEnumerable < Test::Unit::TestCase
bug5801 = '[ruby-dev:45041]'
@empty.grep(//)
- assert_nothing_raised(bug5801) {100.times {@empty.block.call}}
+ block = @empty.block
+ assert_nothing_raised(bug5801) {100.times {block.call}}
a = []
lambda = ->(x, i) {a << [x, i]}
@@ -201,6 +202,21 @@ class TestEnumerable < Test::Unit::TestCase
assert_equal(1, @obj.first)
assert_equal([1, 2, 3], @obj.first(3))
assert_nil(@empty.first)
+
+ bug5801 = '[ruby-dev:45041]'
+ assert_in_out_err([], <<-'end;', [], /unexpected break/)
+ empty = Object.new
+ class << empty
+ attr_reader :block
+ include Enumerable
+ def each(&block)
+ @block = block
+ self
+ end
+ end
+ empty.first
+ empty.block.call
+ end;
end
def test_sort
@@ -440,7 +456,8 @@ class TestEnumerable < Test::Unit::TestCase
bug5801 = '[ruby-dev:45040]'
@empty.take_while {true}
- assert_nothing_raised(bug5801) {100.times {@empty.block.call}}
+ block = @empty.block
+ assert_nothing_raised(bug5801) {100.times {block.call}}
end
def test_drop
diff --git a/vm.c b/vm.c
index fc135b00fa..408dc6dc13 100644
--- a/vm.c
+++ b/vm.c
@@ -44,7 +44,7 @@ rb_vm_search_cf_from_ep(const rb_thread_t * const th, rb_control_frame_t *cfp, c
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
}
- rb_bug("rb_vm_search_cf_from_ep: no corresponding cfp");
+ return NULL;
}
}
@@ -1201,6 +1201,12 @@ vm_iter_break(rb_thread_t *th, VALUE val)
VALUE *ep = VM_CF_PREV_EP(cfp);
rb_control_frame_t *target_cfp = rb_vm_search_cf_from_ep(th, cfp, ep);
+#if 0 /* raise LocalJumpError */
+ if (!target_cfp) {
+ rb_vm_localjump_error("unexpected break", val, TAG_BREAK);
+ }
+#endif
+
th->state = TAG_BREAK;
th->errinfo = (VALUE)THROW_DATA_NEW(val, target_cfp, TAG_BREAK);
TH_JUMP_TAG(th, TAG_BREAK);