-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Unsoundness due to invalid inheritance being permitted #5817
New issue
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
Comments
@smarter quick question - is this refchecks? |
The fix for #3989 was done in refchecks so it would make sense to do the same here I guess. |
Rename the object Test {
trait A[+X] { def x: X }
class B[+X](val x: X) extends A[X]
class C[+X](y: Any) extends B[Any](y) with A[X]
def get(a: A[Int]): Int = a.x
get(new C[Int]("foo")) // class cast exception: String is not Int
} You get:
There's a special code path in PostTyper that merges the values of |
Link for anyone looking for it: https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala |
I got as far as avoiding the param forwarder, but the problem persists. So this goes deeper. |
Looks like this is fixed in at least 3.0.1:
Maybe with #11133? |
Note that we previously came to the conclusion that we do not want to prevent inheritance like
C
in general: #3989.The likely fix would be to require
C
to overrideB#x
- this is precisely what Scalac does.The text was updated successfully, but these errors were encountered: