-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Unexpected semantics of non-nested varargs pattern #17443
Comments
Scala 2 says:
|
To give some context: I found the problem while trying to understand the current syntax specification of pattern matching. Pattern ::= Pattern1 { ‘|’ Pattern1 }
Pattern1 ::= PatVar ‘:’ RefinedType
| [‘-’] integerLiteral ‘:’ RefinedType
| [‘-’] floatingPointLiteral ‘:’ RefinedType
| Pattern2
Pattern2 ::= [id ‘@’] InfixPattern [‘*’]
InfixPattern ::= SimplePattern { id [nl] SimplePattern }
SimplePattern ::= PatVar
| Literal
| ‘(’ [Patterns] ‘)’
| Quoted
| SimplePattern1 [TypeArgs] [ArgumentPatterns]
| ‘given’ RefinedType
SimplePattern1 ::= SimpleRef
| SimplePattern1 ‘.’ id
PatVar ::= varid
| ‘_’
Patterns ::= Pattern {‘,’ Pattern}
ArgumentPatterns ::= ‘(’ [Patterns] ‘)’
| ‘(’ [Patterns ‘,’] PatVar ‘*’ ‘)’ Unless I got something wrong, this seems to allow not only This specification also seems to be out of sync with the comments in Pattern ::= Pattern1 { ‘|’ Pattern1 }
Pattern1 ::= PatVar Ascription
| [‘-’] integerLiteral Ascription
| [‘-’] floatingPointLiteral Ascription
| Pattern2
Pattern2 ::= [id ‘@’] Pattern3
Pattern3 ::= InfixPattern
| PatVar ‘*’ Beside the fact that For reference the syntax for scala 2.13.10 is as follows: Pattern ::= Pattern1 { ‘|’ Pattern1 }
Pattern1 ::= boundvarid ‘:’ TypePat
| ‘_’ ‘:’ TypePat
| Pattern2
Pattern2 ::= id [‘@’ Pattern3]
| Pattern3
Pattern3 ::= SimplePattern
| SimplePattern {id [nl] SimplePattern}
SimplePattern ::= ‘_’
| varid
| Literal
| StableId
| StableId ‘(’ [Patterns] ‘)’
| StableId ‘(’ [Patterns ‘,’] [id ‘@’] ‘_’ ‘*’ ‘)’
| ‘(’ [Patterns] ‘)’
| XmlPattern
Patterns ::= Pattern {‘,’ Patterns} |
I agree, |
Syntax: Remove outdated `*` after InfixPattern Parsing: Only allow vararg `*` in ArgumentPatterns Fixes scala#17443
Syntax: Remove outdated `*` after InfixPattern Parsing: Only allow vararg `*` in ArgumentPatterns Fixes scala#17443
Syntax: Remove outdated `*` after InfixPattern Parsing: Only allow vararg `*` in ArgumentPatterns Fixes #17443
Compiler version
3.3.1-RC1-bin-20230508-830230f-NIGHTLY and before
Minimized code
Output
Expectation
Most probably patterns like
case (xs*) =>
should be illegal, just ascase xs* =>
is. @odersky Can you confirm?In the code snippets above the type of
x
gets inferred toSeq[List[Int]]
but its value isList(1)
, which doesn't make sense and causes theClassCastException
.Also, the warning from the second snippet is wrong at the moment as the case reported as unreachable is actually the one that gets matched.
The text was updated successfully, but these errors were encountered: