-
-
Notifications
You must be signed in to change notification settings - Fork 925
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 { |a,| a } seems to parse incorrectly a unnamed rest arg #3214
Comments
I don't think it is the same - I remember doing some work on this but that's all I remember. |
@chrisseaton It is different at least in the case of a, = 1, 2
a # => 1
# But
lambda { |a,| a }.call([1,2]) # => [1,2] |
I swear this used to be equivalent to
However it does appear to be equivalent in the case of multiple assignment, which may be where @enebo and I are confused (since masgn used to be used for block args too):
We do parse them the same in the lambda case, as a UnnamedRestNode. In the masgn case, they parse differently:
|
@eregon There is in fact a difference and even a comment about the difference (although not a totally obvious comment). Both a,* and a, create an UnnamedRestArgNode. a, will give the name as null and a,* will give the name as "". So goofy I know but AST it able to differentiate the two cases. |
@enebo Good to know, that's the way to differentiate :) But should there be a rest arg in the first place if nothing exhibit its presence? lambda { |a,| a }.call(1,2)
-e:1:in `block in <main>': wrong number of arguments (2 for 1) (ArgumentError) (of course proc allows it, but without the Arity reflects it as shown above, |
As per irc discussion proc will destructure the array passed in and lambda will not. So there is a need to syntactically differentiate |a,| vs |a|. |
And the way to check it from a
So in the end it's just confusing because lambdas behave as if there was never a |
And
I think
|a,|
is just the same as|a|
, is there any difference?This could also be the cause more or less indirectly for the new truffle failures:
https://travis-ci.org/jruby/jruby/jobs/73873458
The text was updated successfully, but these errors were encountered: