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

Lambda with arity -2 can be called with three arguments in 9K #2441

Closed
iconara opened this issue Jan 8, 2015 · 7 comments
Closed

Lambda with arity -2 can be called with three arguments in 9K #2441

iconara opened this issue Jan 8, 2015 · 7 comments

Comments

@iconara
Copy link
Contributor

@iconara iconara commented Jan 8, 2015

This code fails with ArgumentError in MRI (at least since 1.9.3) and JRuby 1.7, but not in JRuby 9K:

lambda { |a, b=nil| }.call(1, 2, 3)

In JRuby 9K (and MRI 1.8.7 I believe) the block is run with 1 and 2 as the values of a and b, the 3 is discarded.

@headius
Copy link
Member

@headius headius commented Jan 8, 2015

I have to ask...how does this affect you?

@iconara
Copy link
Contributor Author

@iconara iconara commented Jan 8, 2015

It's mostly an inconsistency that I accidentally caught when a test started failing.

It's a test for a piece of code that tries to figure out how many arguments it can pass to a listener (which can be a block, a lambda, a method, or anything callable). When the arity is -2 it can't really know how many are ok to pass so it just tries to call the method. In 9K the listener is called, but in previous versions of JRuby and in MRI there's an ArgumentError.

If I could choose I'd like all Rubies to work like 9K, but I thought I'd report it since it's an inconsistency with MRI.

@iconara
Copy link
Contributor Author

@iconara iconara commented Jan 8, 2015

The reason why I'm doing the arity checking at all is for backwards compatibility. A previous version called the listeners with other arguments.

@enebo enebo added this to the JRuby 9.0.0.0 milestone Jan 8, 2015
@enebo
Copy link
Member

@enebo enebo commented Jan 8, 2015

I would like to see this solved before we entertain call protocol changes in IR for blocks which will not happen for 9k.0 but still we should fully nail all semantics of blocks down before trying to tackle it.

@headius
Copy link
Member

@headius headius commented Jan 9, 2015

Ok...this is likely a (reasonably) simple problem with arity-checking in lambdas. We'll get it fixed up, because there's other logic that depends on lambdas enforcing arity strictly.

cc @enebo @subbuss

@headius
Copy link
Member

@headius headius commented Jan 12, 2015

My concern with this is that lambdas have always raised arity errors, and if they aren't now we've got a significant behavioral difference. It's a difference most people won't see, but I don't like it anyway.

@headius
Copy link
Member

@headius headius commented Jan 13, 2015

Fixed in commits today including b6d996d and 7e82e91.

@headius headius closed this as completed Jan 13, 2015
@headius headius removed this from the JRuby 9.0.0.0 milestone Jan 16, 2015
@headius headius added this to the JRuby 9.0.0.0-pre1 milestone Jan 16, 2015
@headius headius added this to the JRuby 9.0.0.0-pre1 milestone Jan 16, 2015
@headius headius removed this from the JRuby 9.0.0.0 milestone Jan 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants