[Bug #2776] can't return from lambda with outer block

Bug #2776: can’t return from lambda with outer block
http://redmine.ruby-lang.org/issues/show/2776

e$B5/I<<Te(B: _ wanabe
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Low
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-02-21 trunk 26722) [i686-linux]

http://pc12.2ch.net/test/read.cgi/tech/1264635554/685
e$B$G<ALd$5$l$F$$$?$N$G$9$,e(B
1.8 e$B$He(B 1.9 e$B$Ge(B lambda e$B$N5sF0$,0[$J$C$F$$$^$9!#e(B


test.rb

class Foo
def initialize(&func)
@func = lambda(&func)
end
def bar(x)
@func.call(x)
end
end
foo = Foo.new{ |x| return x**2 }
p foo.bar(2)

$ ruby1.8 -v test.rb
ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
4

$ ./ruby -v test.rb
ruby 1.9.2dev (2010-02-21 trunk 26722) [i686-linux]
test.rb:9:in block in <main>': unexpected return (LocalJumpError) from test.rb:6:in call’
from test.rb:6:in bar' from test.rb:10:in

e$B%A%1%C%He(B #2776 e$B$,99?7$5$l$^$7$?!#e(B (by Shyouhei U.)

e$BC4Ev<Te(B Koichi Sasadae$B$+$ie(BYukihiro M.e$B$KJQ99e(B

e$B0[$J$C$F$$$k$N$O;v<B$G$9$,!“$I$A$i$,@5$7$$$+e(B(e$B$”$k$$$ON>J}4V0c$$e(B)e$B$O5DO@$NM>CO$,$"$j$=$&$G$9!#e(B

lambda(&proc)

e$B$Ge(Bproce$B$re(Blambdae$B$KJQ49$G$-$k$+$I$&$+$N0c$$e(B?

http://redmine.ruby-lang.org/issues/show/2776

e$B$J$+$@$G$9!#e(B

At Mon, 22 Feb 2010 13:13:47 +0900,
Shyouhei U. wrote in [ruby-dev:40454]:

e$B0[$J$C$F$$$k$N$O;v<B$G$9$,!"$I$A$i$,@5$7$$$+e(B(e$B$"$k$$$ON>J}4V0c$$e(B)e$B$O5DO@$NM>CO$,$"$j$=$&$G$9!#e(B

lambda(&proc) e$B$Ge(Bproce$B$re(Blambdae$B$KJQ49$G$-$k$+$I$&$+$N0c$$e(B?

e$B$=$&$$$&$3$H$G$9$M!#e(B1.9e$B$re(B1.8e$B$K9g$o$;$k$J$i$3$s$J46$8!#e(B

Index: proc.c

— proc.c (revision 26728)
+++ proc.c (working copy)
@@ -401,12 +401,15 @@ proc_new(VALUE klass, int is_lambda)

 if (procval) {
  • rb_proc_t *proc;
    if (RBASIC(procval)->klass == klass) {
  •  return procval;
    
  • }
  • else {
  •  VALUE newprocval = proc_dup(procval);
    
  •  RBASIC(newprocval)->klass = klass;
    
  •  return newprocval;
    
  •  GetProcPtr(procval, proc);
    
  •  if ((proc->is_lambda != 0) == (is_lambda != 0))
    
  • return procval;
    }
  • procval = proc_dup(procval);
  • RBASIC(procval)->klass = klass;
  • GetProcPtr(procval, proc);
  • proc->is_lambda = is_lambda ? TRUE : FALSE;
  • return procval;
    }

2010e$BG/e(B2e$B7ne(B22e$BF|e(B14:37 Nobuyoshi N.
[email protected]:

lambda(&proc) e$B$Ge(Bproce$B$re(Blambdae$B$KJQ49$G$-$k$+$I$&$+$N0c$$e(B?

e$B$=$&$$$&$3$H$G$9$M!#e(B1.9e$B$re(B1.8e$B$K9g$o$;$k$J$i$3$s$J46$8!#e(B

Proc#lambda? e$B$N%I%-%e%a%s%H$K=q$$$F$"$j$^$9$,!"e(B
1.9 e$B$G$O!"e(BProc e$B%*%V%8%'%/%H$,e(B lambda
e$B$+$I$&$+$H$$$&@-<A$Oe(B
e$B$J$k$Y$/JQ$($J$$$H$$$&%G%6%$%s$K$J$C$F$$$^$9!#e(B

e$B$J$+$@$G$9!#e(B

At Mon, 22 Feb 2010 15:00:34 +0900,
Tanaka A. wrote in [ruby-dev:40456]:

Proc#lambda? e$B$N%I%-%e%a%s%H$K=q$$$F$"$j$^$9$,!"e(B
1.9 e$B$G$O!"e(BProc e$B%*%V%8%’%/%H$,e(B lambda e$B$+$I$&$+$H$$$&@-<A$Oe(B
e$B$J$k$Y$/JQ$($J$$$H$$$&%G%6%$%s$K$J$C$F$$$^$9!#e(B

e$B$J$s$G$=$&JQ$o$C$?$s$G$7$?$C$1e(B?

2010e$BG/e(B2e$B7ne(B22e$BF|e(B19:29 Nobuyoshi N.
[email protected]:

e$B$J$s$G$=$&JQ$o$C$?$s$G$7$?$C$1e(B?

return
e$B$G$I$3$rH4$1$k$+$,JQ2=$9$k$N$C$F!"$U$D$&:$$k$s$8$c$J$$$G$9$+$M$'!#e(B

e$B$G$be(B 1.9 e$B$Ge(B

% ./ruby -ve ’
def m(&b)
p yield
2
end
def n
l = lambda { return 1 }
m(&l)
end
p n

ruby 1.9.2dev (2010-02-22 trunk 26728) [i686-linux]
1

e$B$OJQ$o$C$FJQ$@$J$!!#e(B

e$B%A%1%C%He(B #2776 e$B$,99?7$5$l$^$7$?!#e(B (by _ wanabe)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BRejectede$B$KJQ99e(B

e$B;EMM$G$“$k$h$&$G$9$N$Ge(B Reject e$B$5$;$F$$$?$@$-$^$9!#e(B
e$B65$($F$$$?$@$$$F$”$j$,$H$&$4$6$$$^$7$?!#e(B

http://redmine.ruby-lang.org/issues/show/2776