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
[Ruby 3.0] Reserved for numparams #4323
[Ruby 3.0] Reserved for numparams #4323
Conversation
ad3ed13
to
4a4d488
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.
It looks like there are some test failures with some test code that need to be resolved first.
4a4d488
to
96473c9
Compare
@froydnj fixed the hidden definition generation in the latest commit. |
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.
Thanks for fixing up the CI failures!
@@ -57,7 +57,7 @@ tuple<string, string> MESSAGES[] = { | |||
{"InvalidRegexp", "{}"}, | |||
{"InvalidReturn", "invalid return in class/module body"}, | |||
{"CSendInLHSOfMAsgn", "&. inside multiple assignment destination"}, | |||
{"CantAssignToNumparam", "cannot assign to numbered parameter {}"}, | |||
{"ReservedForNumparam", "{} is reserved for numbered parameter"}, |
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 don't know if this is the best error message, but I think we can fix this in a followup.
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.
Agreed. I used the same message Ruby uses.
Revert: (sorbet#4337) Original: (sorbet#4323) This reverts commit f2f50a0.
Revert: (sorbet#4337) Original: (sorbet#4323) This reverts commit f2f50a0. Co-authored-by: Alexandre Terrasa <583144+Morriar@users.noreply.github.com>
Revert: (sorbet#4337) Original: (sorbet#4323) This reverts commit f2f50a0. Co-authored-by: Alexandre Terrasa <583144+Morriar@users.noreply.github.com>
Revert: (sorbet#4337) Original: (sorbet#4323) This reverts commit f2f50a0. Co-authored-by: Alexandre Terrasa <583144+Morriar@users.noreply.github.com>
* [Ruby 3.0] Add reserved for numparams errors to all usages Revert: (#4337) Original: (#4323) This reverts commit f2f50a0. Co-authored-by: Alexandre Terrasa <583144+Morriar@users.noreply.github.com> * Autocorrect reserved numbered parameters from `_[0-9]` to `arg[0-9]` Co-authored-by: Alexandre Terrasa <583144+Morriar@users.noreply.github.com> * Use errors-with-dup for reserved numparams Co-authored-by: Alexandre Terrasa <583144+Morriar@users.noreply.github.com> * Add tests and builder changes related to endless methods combined with numbered parameters Co-authored-by: Alexandre Terrasa <583144+Morriar@users.noreply.github.com> * Use a new error class to be able to supress reserved numparam errors * Fix numbered parameters test cases Co-authored-by: Alexandre Terrasa <583144+Morriar@users.noreply.github.com>
This PR implements the changes for Ruby 3.0 to numbered parameters based on whitequark/parser#725.
The change is to check that the reserved names for numbered parameters are not used anywhere except for numbered parameters themselves.
I had to update some unrelated RBIs and tests because they used these reserved names and started throwing the new error. It might be easier to review per commit.
Motivation
In Ruby 2.7, assigning a numbered parameter would throw an error only inside blocks. That is
Since Ruby 3.0, the numbered parameter names are actually reserved everywhere. Trying to use
_1
as a variable, method definition or any type of argument will throw an error and the message has changed.Test plan
See included automated tests.