In the following example, the last case is inferred to be of type Any (and therefore does not compile), whereas for both checks T is a common supertype:
object X extends App {
def f(a: Any): Unit = a match {
case a: T1 =>
g(a)
case a @ (_: T with S) =>
g(a)
case a @ (_: T with S | _: T1) =>
g(a)
}
def g(t: T): T = t
}
trait S
trait T
trait T1 extends T
In the following example, the last case is inferred to be of type Any (and therefore does not compile), whereas for both checks T is a common supertype: