Open
Description
Compiler version
scala 3.7.1
Minimized code
case class Id1[A](val x: A)
case class Id2[A](val y: A)
type IdAll[A] = Id1[A] | Id2[A]
sealed trait Adt[A]
case class Con1[B >: Id1[A], A](x: A) extends Adt[B]
case class Con2[B >: Id2[A], A](x: A) extends Adt[B]
def test[A, T >: IdAll[A]](expr: Adt[T]): A = {
expr match
case Con1(x) => x
case Con2(x) => x
}
val result = test[Int, IdAll[Int] | Id2[String]](Con2(""))
print(result)
Output
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Integer
Expectation
Compiler error, because the lower bound of IdAll[A]
does not guarantee that type T
will not contain any Id2[B]
, which results in a bounds conflict.