# \[Bug #2657\] rubyspec: The return keyword within define\_method goes through the method via a closure

**URL:** <https://www.ruby-forum.com/t/bug-2657-rubyspec-the-return-keyword-within-define-method-goes-through-the-method-via-a-closure/182305>\
**Category:** Development\
**Created:** [January 26, 2010, 11:59am UTC](https://www.ruby-forum.com/t/bug-2657-rubyspec-the-return-keyword-within-define-method-goes-through-the-method-via-a-closure/182305 "2010-01-26T11:59:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yusuke\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f08c70/32.png) [@Yusuke\_E](https://www.ruby-forum.com/u/Yusuke_E)\
**Post date:** [January 26, 2010, 11:59am UTC](https://www.ruby-forum.com/t/bug-2657-rubyspec-the-return-keyword-within-define-method-goes-through-the-method-via-a-closure/182305/1 "2010-01-26T11:59:58Z")

</div>

Bug #2657: rubyspec: The return keyword within define\_method goes  
through the method via a closure FAILED  
[http://redmine.ruby-lang.org/issues/show/2657](http://redmine.ruby-lang.org/issues/show/2657)

e$B5/I\<\<Te(B: Yusuke E.  
e$B%9%F!\<%?%9e(B: Open, e$BM%@hEYe(B: Normal  
e$BC4Ev\<Te(B: Koichi Sasada, e$B%+%F%4%je(B: core, Target version: 1.9.x  
ruby -v: ruby 1.9.2dev (2010-01-26 trunk 26420) [i686-linux]

e$B$5$5$@$5$se(B  
e$B1sF#$G$9!#e(B

rubyspec e$B$N0J2\<$N%(%i!\<$rD4$Y$F$\_$^$7$?!#e(B

1. 

The return keyword within define\_method goes through the method via a  
closure FAILED  
Expected :bad  
to equal :good

/home/mame/work/ruby/spec/rubyspec/language/return\_spec.rb:269:in  
`block (3 levels) in <top (required)>' /home/mame/work/ruby/spec/rubyspec/language/return_spec.rb:4:in `\<top  
(required)\>’

e$B!{LdBje(B

$ ./ruby -e ’  
class C  
define\_method(:foo) do |&x|  
x.call  
end  
def outer  
foo { return :good }  
return :bad  
end  
end  
p C.new.outer  
’  
ok  
:bad

e$B$H$$$&%W%m%0%i%`$,!"e(B:good e$B$G$J$/e(B :bad  
e$B$rI=\<($7$F$7$^$$$^$9!#$D$$$G$Ke(B  
e$BFf$Ne(B ok e$B$b=P$F$$$^$9!#e(B

1.8 e$B$G$Oe(B :good e$B$,=P$^$9$7!"e(Bdefine\_method e$B$re(B def  
e$B$KCV$-49$($k$He(B 1.9 e$B$G$be(B  
:good e$B$,=P$^$9$N$G!"e(B:good e$B$H=P$k$N$,@5$7$=$&$G$9!#e(B

e$B!{860xe(B

rb\_vm\_invoke\_proc e$B$NCf$Ge(B lambda e$B$NCf$Ne(B TAG\_RETURN  
e$B$r;\_$a$F$7$^$&$3$H$,e(B  
e$B860x$G$9!#e(B

e$B$3$N=hM}$O0l8+$9$k$H!"!Ve(Blambda e$BCf$Ne(B return e$B$,e(B lambda  
e$B$G;_$^$k$?$a$Ke(B  
e$BI,MW!W$H;W$C$F$7$^$$$^$9$,!"e(BTAG\_RETURN e$B$OIaDL$Ke(B vm\_exec  
e$B$NCf$G=hM}$5$le(B  
goto finish\_vme; e$B$K$h$C$F;_$a$i$l$^$9$N$G!"ITMW$@$H;W$o$l$^$9!#e(B

e$B$3$N=hM}$,ITMW$G$"$k$3$H$N\>u67\>Z5r$H$7$F!"e(B

- e$B$3$N=hM}$r\>C$7$F$b%F%9%H$N%(%i!\<$OA}$($J$$e(B (e$B\>e5-$Ne(B  
rubyspec e$B$NJ,8:$ke(B)

- e$B%+%P%l%C%8$r8+$F$b!"\>e5-$Ne(B rubyspec  
e$B$N%F%9%H0J30$G$O\<B9T$5$l$F$$$J$$e(B  
([http://dame.dyndns.org:7001/20100126/ruby/vm.c](http://dame.dyndns.org:7001/20100126/ruby/vm.c) e$B$Ne(B  
rb\_vm\_invoke\_proc  
e$B$NCf$N$3$N%A%'%C%/$N%+%P%l%C%8$,e(B 1 e$B2s$@$1e(B)

- e$B$3$N=hM}$K$O%G%P%C%0MQ$Ne(B printf e$BJ8$,;D$C$F$$$ke(B (2008-06-17  
e$B$Ne(B r17390  
e$B$+$i$:$C$He(B) e$B$N$K!"IaDL$Ke(B lambda { return }.call  
e$B$J$I$7$F$b=P2q$o$J$$e(B

e$B$H$$$&$o$1$G!“Ev;~$OI,MW$@$C$?$N$+$b$7$l$^$;$s$,!”\>/$J$/$H$b8=:\_$G$Oe(B  
e$B$3$N=hM}$O32$G$7$+$J$$$H;W$$$^$9!#e(B

e$B!{%Q%C%Ae(B

e$BLdBj$N=hM}$r\>C$7$^$9!#e(B

diff --git a/vm.c b/vm.c  
index bb19ecb…f03cf31 100644  
— a/vm.c  
+++ b/vm.c  
@@ -609,21 +609,6 @@ rb\_vm\_invoke\_proc(rb\_thread\_t \*th, rb\_proc\_t \*proc,  
VALUE self,  
}

```
 if (state) {

```

- if (state == TAG\_RETURN && proc-\>is\_lambda) {
- 

```
 VALUE err = th->errinfo;

```

- 

```
 VALUE *escape_dfp = GET_THROWOBJ_CATCH_POINT(err);

```

- 
- 

```
 if (escape_dfp == cfp->dfp) {

```

- printf(“ok\n”);
- state = 0;
- th-\>errinfo = Qnil;
- th-\>cfp = cfp;
- val = GET\_THROWOBJ\_VAL(err);
- 

```
 }

```

- }
- }
- 
- if (state) {  
JUMP\_TAG(state);  
}  
return val;

–  
Yusuke ENDOH [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Yusuke\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f08c70/32.png) [@Yusuke\_E](https://www.ruby-forum.com/u/Yusuke_E)\
**Post date:** [January 26, 2010, 12:10pm UTC](https://www.ruby-forum.com/t/bug-2657-rubyspec-the-return-keyword-within-define-method-goes-through-the-method-via-a-closure/182305/2 "2010-01-26T12:10:30Z")

</div>

e$B!!$5$5$@$G$9!%e(B

(2010/01/26 19:59), Yusuke E. wrote::

> e$B$3$N=hM}$O32$G$7$+$J$$$H;W$$$^$9!#e(B  
> e$B!!$O$$!%6D$kDL$j$+$H;W$$$^$9!%=$@5$7$F2\<$5$$$^$;!%e(B

---

<div class="post-metadata">

**Author:** ![Yusuke\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f08c70/32.png) [@Yusuke\_E](https://www.ruby-forum.com/u/Yusuke_E)\
**Post date:** [January 26, 2010, 12:39pm UTC](https://www.ruby-forum.com/t/bug-2657-rubyspec-the-return-keyword-within-define-method-goes-through-the-method-via-a-closure/182305/3 "2010-01-26T12:39:11Z")

</div>

e$B%A%1%C%He(B #2657 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

e$B%9%F!\<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B  
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

This issue was solved with changeset r26425.  
Yusuke, thank you for reporting this issue.  
Your contribution to Ruby is greatly appreciated.  
May Ruby be with you.

* * *

[http://redmine.ruby-lang.org/issues/show/2657](http://redmine.ruby-lang.org/issues/show/2657)
