-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix #8715: enforce syntax for _* #8732
Conversation
Previously we didn't check that _* is indeed the last argument, checking for ")" is not enough, as ")" may be the closing parenthsis of a nested pattern.
Previous only typing errors related to _* are annotated, now we also have parsing errors related to _*. Fix test
The code `text format (args : _*)` is invalid by Dotty syntax, we tolerate it for migration from Scala2.
We are not compiling stdlib with `-source 3.0-migration`, thus we need to change the syntax.
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.
The changes look correct. But I do not like that they add extra state to the parser. In this case, I believe we can get around it by adding a new value InArgumentList
to Location
. location
values are propagated to ascription
where we can check for it. They are not propagated to simplePatterm
but I think we can leave the old incomplete check there as long a we warn that this is no longer supported.
@@ -2009,7 +2017,14 @@ object Parsers { | |||
val uscoreStart = in.skipToken() | |||
if (isIdent(nme.raw.STAR)) { | |||
in.nextToken() | |||
if (in.token != RPAREN) syntaxError(SeqWildcardPatternPos(), uscoreStart) | |||
if in.token != RPAREN || !inArguments && sourceVersion.isAtLeast(`3.1`) then | |||
syntaxError(SeqWildcardPatternPos(), uscoreStart) |
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.
Maybe be more aggressive and demand this for 3.0? In any case, we should do migration warning and it would be nice to also offer a rewrite.
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.
In fact, I believe the warning that this is no longer supported is more important than the error that it's in the wrong place. The theory is that any code that has xs @ _*
will have already been compiled by Scala 2 (in most cases, at least)
Thanks for the tip @odersky , I'll try the suggested fix. |
Close in favor of #8753, which is more elegant. |
Fix #8715: enforce syntax for _*
Previously we didn't check that _* is indeed the last argument,
checking for ")" is not enough, as ")" may be the closing parenthsis
of a nested pattern.