Running jruby 184.108.40.206 (2.3.1) 2016-09-07 036ce39 OpenJDK 64-Bit Server VM 25.91-b14 on 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14 [linux-x86_64] on Linux maruchan 4.8.0-16-generic #17-Ubuntu SMP Thu Sep 22 22:48:49 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux.
jruby 220.127.116.11 (2.3.1) 2016-09-07 036ce39 OpenJDK 64-Bit Server VM 25.91-b14 on 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14 [linux-x86_64]
Linux maruchan 4.8.0-16-generic #17-Ubuntu SMP Thu Sep 22 22:48:49 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
def foo(a = 'default a', b:)
foo(a: 'some value', b: 'some value')
Output in MRI 2.3.1:
ArgumentError: unknown keyword: a
Output in JRuby (return from function)
["default a", "some value"]
ok I know the problem and I will describe it as the actual fix might take a little thought. We allocate lvars and kwargs using the same StaticScope storage. We depend on strings which represent the variable name. So we do not complain about 'a:' since opt arg 'a=' exists. This seemed safe since you cannot actually have a method like:
def foo(a=1, a:)
The parser realizes that you are trying to use the same name in two different ways which is ambiguous. What the current solution did not consider is that we need to know if a particular name is a kwarg or an ordinary arg. So there are many ways to skin this cat but it means some extra state somewhere. Most obvious thought would be a kwargs start at offset x field. Then if we find 'a' exists before that we know it is not a kwarg?
Fixes #4186. JRuby accepts wrong method arguments when mixing positional
with defaults and keywords.
StaticScopes now keep track of where keyword arguments start by index.
This is missing a regression test which I will add in next commit.
Wow, blazing fast fix! Thanks! 😄
Fallout from #4186. JRuby AOT and IR persistence needs to persist the…
fistKeywordIndex field in StaticScope.
@ivoanjo I thought I had fixed all keyword argument bugs relating to methods (we have some other issues still with blocks) in our last point release so I was determined!