Closed
Description
class A
class B
class C
object Test {
def foo(x: A) = x match {
case x: B => x // as expected, error: this case is unreachable since class A is not a subclass of class B
case _ =>
}
def bar(x: A | B) = x match {
case x: C => x // no error!
case _ =>
}
}
The logic handling this is in TypeTestCast#interceptTypeApply#interceptWith#transformIsInstanceOf
which computes a class symbol for the scrutinee:
def foundCls = effectiveClass(expr.tpe.widen)
So when the pattern has type A | B
, testCls
will be Any
. This logic needs to be adapted to handle union types where there's more than one possible class symbol.