Closed
Description
Compiler version
scala 3.1.1
Minimized code
This code compiles, and fails at runtime with a MatchError:
val (n, m) = (1, 2) match {
case _ => 1
case null => (1,2)
}
val (n, m) = (1, 2) match {
case pair if false => (1,2)
case other => 1
}
Output
Fails with scala.MatchError: 1 (of class java.lang.Integer)
Expectation
The code should not compile; the return 1
cannot be destructured into a Tuple2
For comparison, the following code does not compile:
// cannot test if value of type (1 : Int) | (2 : Int) is a reference of class Tuple2
val (n, m) = (1, 2) match {
case _ => 1
case null => 2
}
// cannot test if value of type Int is a reference of class Tuple2
val (n, m) = (1, 2) match {
case _ => 1
case null => ???
}
// cannot test if value of type Int is a reference of class Tuple2
val (n, m) = (1, 2) match {
case _ => 1
}