Passing nil as the value of a keyword argument causes JRuby to act as if there were no such keyword argument #1047

Closed
97jaz opened this Issue Sep 30, 2013 · 2 comments

Projects

None yet

2 participants

@97jaz
Contributor
97jaz commented Sep 30, 2013

The following simple program demonstrates the problem:

def test(foo: 10)
  foo
end

test(foo: nil)

MRI:

2.0.0p247 :006 > test(foo: nil)
 => nil

JRuby:

jruby-1.7.4 :005 >   test(foo: nil)
ArgumentError: unknown keyword: foo
    from (irb):5:in `evaluate'
    from org/jruby/RubyKernel.java:1093:in `eval'
    from org/jruby/RubyKernel.java:1489:in `loop'
    from org/jruby/RubyKernel.java:1254:in `catch'
    from org/jruby/RubyKernel.java:1254:in `catch'
    from /Users/jaz/.rvm/rubies/jruby-1.7.4/bin/irb:13:in `(root)'
@97jaz
Contributor
97jaz commented Sep 30, 2013

The cause appears to be the conditional at: https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/ast/ArgsNode.java#L488

This code needs to distinguish between the absence of a keyword value and an explicitly provided nil. I should be able to provide a patch, I think.

@97jaz 97jaz added a commit to 97jaz/jruby that referenced this issue Sep 30, 2013
@97jaz 97jaz Fixes JRuby #1047 - incorrect test for whether a kw arg was provided.
Formerly, the code attempted to extract the argument value from the
hash of provided values and test it against nil. This fails in the
case of an explicitly passed nil. The new version instead tests
whether the hash contains the desired key.
21248c4
@headius
Member
headius commented Oct 1, 2013

Fixed by #1054.

@headius headius closed this Oct 1, 2013
@headius headius added a commit that referenced this issue Oct 1, 2013
@97jaz @headius 97jaz + headius Fixes JRuby #1047 - incorrect test for whether a kw arg was provided.
Formerly, the code attempted to extract the argument value from the
hash of provided values and test it against nil. This fails in the
case of an explicitly passed nil. The new version instead tests
whether the hash contains the desired key.
8d74e67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment