-
Notifications
You must be signed in to change notification settings - Fork 565
[RFC] Do not error on **kwargs
parameters name mismatch
#5142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
**kwargs
parameters name mismatch**kwargs
parameters name mismatch
58d9100
to
3cd1ae1
Compare
At first I misread this PR, thinking that you were attempting to make def foo(x:, y:); end
def foo(**kwargs); end not report an error. That doesn't seem to be the case, and I'm generally on board with this idea now knowing what it really does. There's a problem with your implementation:
You're just papering over the symptoms, but not actually addressing the root cause. What we see in this symbol-table output is that there are two
The We have solved a similar problem in the past for positional args: you'll notice that def foo(x); end
def foo(y); end reports no error. The way that this is done is that all positional args are given a name of the form Line 851 in 3cd1ae1
The original argument name is not actually stored in in the symbol table—the only time it's ever needed is for error messages, and for that, we use a clever trick: we record the Lines 1571 to 1573 in 3cd1ae1
We should do something similar with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally on board.
ef07189
to
54ae15f
Compare
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
54ae15f
to
26de81c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beautiful, thanks!
@@ -1085,7 +1085,7 @@ class Builder::Impl { | |||
core::NameRef nm; | |||
|
|||
if (name != nullptr) { | |||
loc = loc.join(tokLoc(name)); | |||
loc = tokLoc(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a minor thing, but instead of overwriting loc
in just this case, do you mind changing it so that loc
is not given an initial value, and instead it's written to once in each of the if
branches?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i went ahead and did this. it'll merge when the tests pass.
We have a policy of testing changes to Sorbet against Stripe's codebase before Stripe employees can see the build results here: → https://go/builds/bui_LKnzZEzNmX3HKm |
Motivation
When Sorbet is checking methods redefinitions, it errors on mismatching names for keyword arguments and
**kwargs
:While this verification makes sense for keyword arguments (they should be the same in all the definitions of the same methods), I'm not sure it applies to
**kwargs
.Consider the following case:
The renaming in the shim file should be allowed as it still is compatible with the generated definition for
View#render
.Implementation
Added a possible implementation for this change to see what else would break.
Test plan
See included automated tests.