-
Notifications
You must be signed in to change notification settings - Fork 581
Use <restargs> instead of *
#9761
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
base: master
Are you sure you want to change the base?
Conversation
| call do |m, a,| # error: Method `call` does not exist | ||
| stuff # error: Method `stuff` does not exist | ||
| call do |m, a,| | ||
| # error: Anonymous rest parameter in block args |
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.
If it was call do |m, a, *| it would have been caught.
This error should have been here all along, but wasn't detected. Now it is.
| # error: Anonymous rest parameter in block args | ||
| T.reveal_type(k) # error: `String` | ||
| end | ||
| opts.each do |k, _| |
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 might be a mistake. This isn't a block rest arg, just another named positional argument that happens to be called _.
I suspect this was intended:
| opts.each do |k, _| | |
| opts.each do |k, *| | |
| # error: Anonymous rest parameter in block args |
b675412 to
b91a30b
Compare
jez
left a comment
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 breaking change. Sorbet currently permits this code.
# typed: true
extend T::Sig
sig {params("*": T.untyped).void}
def foo(*)
endNo errors! Great job.
(If we don't have a test for that, we should.)
We should not regress this for an appeal to internal consistency: parameter names have meaning.
|
@jez Agreed, Sorbet should have a test for that. How about we rewrite the sig to continue supporting the |
Motivation
Benefits:
def foo(**)is confusing in dusugar tree outputImproves consistency with implicit block rest args:
I have follow-up PRs that make similar changes to
**(#9766) and&(#9762).Test plan
Covered by existing tests.