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

Keyword arguments arity issue #2480

Closed
emboss opened this Issue Jan 19, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@emboss

emboss commented Jan 19, 2015

Probably related to #2320. I get similar results with lambda keyword arguments and keyword arguments passed as a Hash instead of passing them explicitly.

$ jruby -v
jruby 9.0.0.0.pre1 (2.2.0p0) 2015-01-18 746583b Java HotSpot(TM) 64-Bit Server VM 25.25-b02 on 1.8.0_25-b17 +jit [linux-amd64]
l = lambda  { |a:| a }
l.call(a: 1) # wrong number of arguments (1 for 0)
l.arity # 0 (1 in MRI 2.2.0p0)

After some debugging, I found out that in RubyBlock#prepareArgs the arity is checked on the Signature's arity object (a "Fixed0"), but keyword args would only be considered in Signature#checkArity.

Not sure if this is related or a different issue:

def m(a:, b:); a + b; end
args = { a: 1, b: 2 }
m(args) # ArgumentError: missing keyword: a
method(:m).arity # 0 (1 in MRI 2.2.0p0)

@enebo enebo added this to the JRuby 9.0.0.0 milestone Jan 19, 2015

@enebo

This comment has been minimized.

Show comment
Hide comment
@enebo

enebo Jan 19, 2015

Member

In your second m(args) snippet I see no argument error but the arity is 0 like you reported. Can you confirm that?

Member

enebo commented Jan 19, 2015

In your second m(args) snippet I see no argument error but the arity is 0 like you reported. Can you confirm that?

@enebo

This comment has been minimized.

Show comment
Hide comment
@enebo

enebo Jan 19, 2015

Member

Commit 2025534 solves the ArgumentError in your first snippet but does not fix your arity issue. Going to look at arity tests in MRI and see what we have tagged out.

Member

enebo commented Jan 19, 2015

Commit 2025534 solves the ArgumentError in your first snippet but does not fix your arity issue. Going to look at arity tests in MRI and see what we have tagged out.

@emboss

This comment has been minimized.

Show comment
Hide comment
@emboss

emboss Jan 19, 2015

Awesome, thank you! About the second example, it's weird. I was running this in irb, when I tried again it worked. But I found a script that reproduces it deterministically on my machine:

def f(a:, b:); end
args = { a: 1, b: 1 }
f(args) # nil, first invocation works
f(args) # ArgumentError: Missing keyword :a

It's only the second call that fails.

emboss commented Jan 19, 2015

Awesome, thank you! About the second example, it's weird. I was running this in irb, when I tried again it worked. But I found a script that reproduces it deterministically on my machine:

def f(a:, b:); end
args = { a: 1, b: 1 }
f(args) # nil, first invocation works
f(args) # ArgumentError: Missing keyword :a

It's only the second call that fails.

@enebo

This comment has been minimized.

Show comment
Hide comment
@enebo

enebo Jan 20, 2015

Member

AHA. So for this example we will track it at #2015 and for the arity cases we will use this issue.

Member

enebo commented Jan 20, 2015

AHA. So for this example we will track it at #2015 and for the arity cases we will use this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment