diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 3398b95..3f5cd94 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1527,6 +1527,7 @@ vm_throw(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_control_frame_t *cfp = GET_CFP(); VALUE *dfp = GET_DFP(); VALUE *lfp = GET_LFP(); + int in_class_frame = 0; /* check orphan and get dfp */ while ((VALUE *) cfp < th->stack + th->stack_size) { @@ -1534,6 +1535,7 @@ vm_throw(rb_thread_t *th, rb_control_frame_t *reg_cfp, lfp = cfp->lfp; } if (cfp->dfp == lfp && cfp->iseq->type == ISEQ_TYPE_CLASS) { + in_class_frame = 1; lfp = 0; } @@ -1541,6 +1543,12 @@ vm_throw(rb_thread_t *th, rb_control_frame_t *reg_cfp, if (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_LAMBDA) { VALUE *tdfp = dfp; + if (in_class_frame) { + /* lambda {class A; ... return ...; end} */ + dfp = cfp->dfp; + goto valid_return; + } + while (lfp != tdfp) { if (cfp->dfp == tdfp) { /* in lambda */ diff --git a/bootstraptest/test_proc.rb b/bootstraptest/test_proc.rb index 28a2377..1ad8a9d 100644 --- a/bootstraptest/test_proc.rb +++ b/bootstraptest/test_proc.rb @@ -429,3 +429,29 @@ assert_equal 'ok', %q{ raise "ok" } +assert_equal 'ok', %q{ + lambda do + class A + class B + proc{return :ng}.call + end + end + end.call + :ok +} + +assert_equal 'ok', %q{ + $proc = proc{return} + begin + lambda do + class A + class B + $proc.call + end + end + end.call + :ng + rescue LocalJumpError + :ok + end +}