Closed
Description
Minimized code
case class A(a: Int)
case class B(b: Int)
case class C(c: Int)
val a = (A(1): A) match {
case A(_) => "OK"
case B(_) => "NOT OK" // Compiler Error: this case is unreachable since class A and class B are unrelated
}
val b = (A(1): A | B) match {
case A(_) => "OK"
case B(_) => "OK"
case C(_) => "NOT OK" // No Compiler Error
}
Output
[error] | case B(_) => "NOT OK"
[error] | ^
[error] | this case is unreachable since class A and class B are unrelated
Expectation
The compiler should also yield an unreachable code error for the second match statement when trying to match on C
since it's not related to type A | B
.