Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
JRuby accepts wrong method arguments when mixing positional with defaults and keywords #4186
def foo(a = 'default a', b:) [a, b] end def bar foo(a: 'some value', b: 'some value') end bar
Output in MRI 2.3.1:
Output in JRuby (return from function)
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:) end
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?