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

Pattern matching in `val` should perform type cast #11800

Open
Atry opened this issue Nov 13, 2019 · 0 comments
Open

Pattern matching in `val` should perform type cast #11800

Atry opened this issue Nov 13, 2019 · 0 comments

Comments

@Atry
Copy link

@Atry Atry commented Nov 13, 2019

Welcome to Scala 2.13.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_181).
Type in expressions for evaluation. Or try :help.

scala> val a: Any = 1
a: Any = 1

scala> val _ @ b : Int = a
                         ^
       error: type mismatch;
        found   : Any
        required: Int

scala> val (c: Int) = a
                      ^
       error: type mismatch;
        found   : Any
        required: Int

I expect it compiles because _ @ b : Int is not a simple name nor a name followed by a colon and a type. According to SLS 4.1, it should be expanded to the following code.

val b = a match {
  case _ @ x$1 : Int =>
    x$1
}

Also (c: Int) should compile as well since it is not a simple name nor a name followed by a colon and a type.

This bug is similar to #10315

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.