Fixes for keyword argument handling#1054
Fixes for keyword argument handling#105497jaz wants to merge 2 commits intojruby:masterfrom 97jaz:1049-kwargs
Conversation
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.
|
@97jaz if rubyspec doesn't already cover these cases, you should try sending a pull request there. https://github.com/rubyspec/rubyspec/blob/master/language/def_spec.rb |
|
Thanks. I'll take a look. |
|
I submitted a PR to rubyspecs. See: https://github.com/rubyspec/rubyspec/pull/255 |
There were two basic problems with the existing logic: * Arguments could be treated both as kw args and as, e.g., optional args. * An arity check for methods with kw arguments in the Arity class is deferred to asignment time, but the check was not being performed there, either.
|
Thanks! The changes look good. We also need to fix the compiler side. You can look into that or I can do it. We're releasing 1.7.5 within the next day, so I'm going to make sure this doesn't affect non-2.0 modes at all before merging. I don't think it will, since there's no keywords in 1.8 or 1.9 mode. |
|
Merged, thanks! When we start hitting 2.0/2.1 logic hard after 1.7.5, I'll get the compiler bits worked out...or you can have a look if you like :-) |
|
Thanks! I haven't looked at the compiler yet, but I'll try to take a look at it tomorrow. |
[Fixes #1047, #1049. This supersedes my previous PR: 1047-kwargs.]
... should produce nil.
...should produce [{:no=>"way"}, 10]
... should raise an ArgumentError.
... should produce [true, 78]
and
... should produce [[], 3]
I would be more than happy to add these examples as tests, but I can't tell how I would add 2.0-specific tests. If someone could point me in the right direction, I'll add tests to this PR.