Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when lambdas are converted to blocks #1559

Closed
alexrothenberg opened this issue Mar 13, 2014 · 2 comments
Closed

Bug when lambdas are converted to blocks #1559

alexrothenberg opened this issue Mar 13, 2014 · 2 comments
Milestone

Comments

@alexrothenberg
Copy link

While discussing a weird issue around treating lambdas as blocks in MRI (https://bugs.ruby-lang.org/issues/9605) @nobu found this odd behavior in jruby.

In jruby lambdas converted to blocks behave differently depending on whether they were created with the lambda or -> syntax.

  1. As expected lambdas enforce arity with both syntaxes when called.

    $ jruby -v -e 'def test(l); l.call(1); end; test(lambda{p :ng})'
    jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot(TM) 64-Bit Server VM 1.7.051-b13 [darwin-x8664]
    ArgumentError: wrong number of arguments (1 for 0)
    call at org/jruby/RubyProc.java:267
    test at -e:1
    (root) at -e:1
    
    $ jruby -v -e 'def test(l); l.call(1); end; test(->(){p :ng})' 
    jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot(TM) 64-Bit Server VM 1.7.051-b13 [darwin-x8664]
    ArgumentError: wrong number of arguments (1 for 0)
    call at org/jruby/RubyProc.java:267
    test at -e:1
    (root) at -e:1
    
  2. Surprisingly, when converted to a block lambdas behave differently depending on which syntax they were created with. The arity check is gone from those created with lambda

    $ jruby -v -e 'def test; yield 1; end; test(&->(){p :ng})' 
    jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot(TM) 64-Bit Server VM 1.7.051-b13 [darwin-x8664]
    ArgumentError: wrong number of arguments (1 for 0)
    test at -e:1
    (root) at -e:1
    
    $ jruby -v -e 'def test; yield 1; end; test(&lambda{p :ng})' 
    jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot(TM) 64-Bit Server VM 1.7.051-b13 [darwin-x8664]
    :ng
    
@rtyler
Copy link

rtyler commented Aug 7, 2015

I believe this is related to #2164 which has also been resolved as of the latest JRuby 9.0.0.0 release:

➜  sandbox  ruby -v -e 'def test; yield 1; end; test(&->(){p :ng})'  
jruby 9.0.0.0 (2.2.2) 2015-07-21 e10ec96 OpenJDK 64-Bit Server VM 25.45-b02 on 1.8.0_45-internal-b14 +jit [linux-amd64]
ArgumentError: wrong number of arguments (1 for 0)
   test at -e:1
  <top> at -e:1
➜  sandbox  ruby -v -e 'def test; yield 1; end; test(&lambda{p :ng})' 
jruby 9.0.0.0 (2.2.2) 2015-07-21 e10ec96 OpenJDK 64-Bit Server VM 25.45-b02 on 1.8.0_45-internal-b14 +jit [linux-amd64]
ArgumentError: wrong number of arguments (1 for 0)
   test at -e:1
  <top> at -e:1
➜  sandbox  

@rtyler rtyler closed this as completed Aug 7, 2015
@alexrothenberg
Copy link
Author

awesome thank you team for fixing this!

@enebo enebo added this to the JRuby 9.0.0.0 milestone Aug 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants