Open
Description
Compiler version
3.3.3
Minimized code
@main
def main(): Unit = {
val example: Tuple2[Int | String, Int | String] = ("test", 2)
example match {
case newExample@Tuple2(a: Int, b: Int) => println("hi")
case other => println("unmatched")
}
}
prints "unmatched" but
@main
def main(): Unit = {
val example: Tuple2[Int | String, Int | String] = ("test", 2)
example match {
case newExample@Tuple2[Int, Int](a: Int, b: Int) => println("hi")
case other => println("unmatched")
}
}
throws a ClassCastException
.
Expectation
While it's understandable that the compiler can't infer the types correctly (this seems to be #15972), I think it's unexpected that just adding a type specifier removes the runtime type checks.