Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

liufengyun
Copy link
Contributor

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.

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.
Copy link
Contributor

@odersky odersky left a 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)
Copy link
Contributor

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.

Copy link
Contributor

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)

@liufengyun
Copy link
Contributor Author

Thanks for the tip @odersky , I'll try the suggested fix.

@liufengyun
Copy link
Contributor Author

Close in favor of #8753, which is more elegant.

@liufengyun liufengyun closed this Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong attempt to rebind a wildcard sequence compiles and results in runtime CCE
2 participants