Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Bug when lambdas are converted to blocks #1559

Open
alexrothenberg opened this Issue · 0 comments

1 participant

@alexrothenberg

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
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.