We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scala 3.7.1
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)
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Integer
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.
IdAll[A]
T
Id2[B]
The text was updated successfully, but these errors were encountered:
Not surprisingly, replacing union types with intersection types, and lower bounds with upper bounds, the issue remains.
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)
Sorry, something went wrong.
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
Compiler version
scala 3.7.1
Minimized code
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 typeT
will not contain anyId2[B]
, which results in a bounds conflict.The text was updated successfully, but these errors were encountered: