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

A case where calling a lambda is different between MRI and JRuby #2164

Closed
iconara opened this issue Nov 9, 2014 · 1 comment
Closed

A case where calling a lambda is different between MRI and JRuby #2164

iconara opened this issue Nov 9, 2014 · 1 comment
Milestone

Comments

@iconara
Copy link
Contributor

iconara commented Nov 9, 2014

When calling a lambda that has a default argument (e.g. lambda { |a, b=nil| }) it is an error in MRI to call it with more than two arguments. In JRuby 1.7.x and 9k the lambda instead acts like it was created with proc and discards the extra arguments:

$ export CODE='lambda { |a, b=nil| p [a, b] }.call(1, 2, 3)'

$ rvm ruby-1.9.3-p448 do ruby -e $CODE
-e:1:in `block in <main>': wrong number of arguments (3 for 2) (ArgumentError)
    from -e:1:in `call'
    from -e:1:in `<main>'

$ rvm ruby-2.0.0-p353 do ruby -e $CODE
-e:1:in `block in <main>': wrong number of arguments (3 for 1..2) (ArgumentError)
    from -e:1:in `call'
    from -e:1:in `<main>'

$ rvm ruby-2.1.2 do ruby -e $CODE
-e:1:in `block in <main>': wrong number of arguments (3 for 1..2) (ArgumentError)
    from -e:1:in `call'
    from -e:1:in `<main>'

$ rvm jruby-1.7.16.1 do ruby -e $CODE
[1, 2]

$ rvm jruby-head do ruby -e $CODE
[1, 2]
@rtyler
Copy link

rtyler commented Aug 7, 2015

This has since been fixed in the latest versions of JRuby (1.7.21, 9k)

[15] pry(main)> lambda { |a, b=nil| p [a, b] }.call(1, 2, 3)
ArgumentError: wrong number of arguments (3 for 2)
from org/jruby/RubyProc.java:271:in `call'
[16] pry(main)> JRUBY_VERSION
=> "1.7.21"
[17] pry(main)> 
[1] pry(main)> lambda { |a, b=nil| p [a, b] }.call(1, 2, 3)
ArgumentError: wrong number of arguments (3 for 2)
from org/jruby/RubyProc.java:306:in `call'
[2] pry(main)> JRUBY_VERSION
=> "9.0.0.0"
[3] pry(main)> 

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