-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Confusion between syntax for pattern alternative and typed pattern on a union type #3332
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
Comments
Without parenthesis, it is parsed as case (s @ _: String) | Int => with parenthesis: case s @ _: String | Int => |
But I think it is more than a parsing issue, the following code snippet compiles with Dotty and crashes at runtime: object Main {
def main(args: Array[String]): Unit = {
(1: Any) match { case (s: String) | _: Int => s }
}
}
|
This code should not compile, as in scalac where you get: try/i3332.scala:3: error: illegal variable in pattern alternative
(1: Any) match { case (s: String) | _: Int => s }
^ There's already an issue for that: #1612 The other issue is how to parse |
Disallow bound variables where the binder appears as a pattern alternative.
Fix #3332: Disallow bound variables in pattern alternatives
As in the title, running this code in REPL throws
java.lang.VerifyError
:Parenthesising the type, however, runs normally:
The text was updated successfully, but these errors were encountered: