The first case is unsound because you underestimate the variety of types in Scala type system. It would make sense if, when we took case i:Int
branch we knew T
was Int
, or at least a supertype of Int
. But it doesn’t have to be! E.g. it could be 42.type or a tagged type.
There’s no such problem in the second case, because from IntExpr <: Expr[T]
, the compiler does know T
must be exactly Int
.