You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The tldr of that issue is for a given function def foo(a=1, b:2)
we get ambiguous args in the validator because the code is forwarding args in the ruby 2.x way. The following invocations appear identical to the verifier, but will cause different function parameter assignments.
Ruby 3
You need to explicitly delegate keyword arguments.
def foo(*args, **kwargs, &block)
target(*args, **kwargs, &block)
end
Alternatively, if you do not need compatibility with Ruby 2.6 or prior and you don’t alter any arguments, you can use the new delegation syntax (...) that is introduced in Ruby 2.7.
def foo(...)
target(...)
end
The fix is that the method signature verifier would need to change to accept the args in one of the two ways described in the snippet I linked in ruby 3 environments.
I am not familiar enough with the rspec code base to understand exactly how large a task that is, but I imagine its not small.
I'm open to having my previous contribution reverted until the fix is ready, since its caused at least one regression.
The text was updated successfully, but these errors were encountered:
Does your fix address the regression?
If so, I suggest merging it, and if more regressions come up - revert both and thinking about a more generic approach to the problem.
My fix does not help (and is mostly a more succinct version of the pull request from JonRowe). My original change which caused the reported regression just relaxed the conditions for which the code would incorrectly identify a positional argument as the keyword argument hash.
Actually I took another try at the fix and I think I have something that is more correct, but does rely on callers using the ruby2_keywords annotation.
Subject of the issue
Cross posting issue: rspec/rspec-expectations#1451
The tldr of that issue is for a given function
def foo(a=1, b:2)
we get ambiguous args in the validator because the code is forwarding args in the ruby 2.x way. The following invocations appear identical to the verifier, but will cause different function parameter assignments.
The change I added to allow non-symbolic keys into the kwargs splat uncovered this bug in a very particular regression, see linked issue at the top for details.
I attempted to fix the issue, but as stated above, ran into the problem of unsolvable ambiguity.
The following is a snippet from the ruby3 docs describing the imcompatibility
https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
Ruby 3
You need to explicitly delegate keyword arguments.
Alternatively, if you do not need compatibility with Ruby 2.6 or prior and you don’t alter any arguments, you can use the new delegation syntax (...) that is introduced in Ruby 2.7.
The fix is that the method signature verifier would need to change to accept the args in one of the two ways described in the snippet I linked in ruby 3 environments.
I am not familiar enough with the rspec code base to understand exactly how large a task that is, but I imagine its not small.
I'm open to having my previous contribution reverted until the fix is ready, since its caused at least one regression.
The text was updated successfully, but these errors were encountered: