-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Freeze GADTs more when comparing type member infos #15869
Conversation
Thanks for the fix! Although this does fix the issues, I think that freezing the GADT constraints when RHS is not an alias cannot cover all unsoundness problems here--since the root cause of the unsoundness is that enum SUB[-A, +B]:
case Refl[C]() extends SUB[C, C]
trait Foo { type A }
def foo[L, H, X <: Foo { type A >: L <: H }](e: SUB[X, Foo { type A = Int }], i: Int): L = e.match {
case SUB.Refl() => i
}
val e0: SUB[Foo { type A = Int }, Foo { type A = Int }] =
SUB.Refl[Foo { type A = Int }]()
def boom(i: Int): String = foo[Nothing, Any, Foo { type A = Int }](e0, i) : Nothing // cast Int to String! Comparing |
Btw, I think we should keep the enum SUB[-A, +B]:
case Refl[C]() extends SUB[C, C]
trait Foo { type A }
def foo[L, H](x: Foo { type A >: L <: H }, e: SUB[x.type, Foo { type A = Int }], i: Int): L = e.match {
case SUB.Refl() => i
}
val x0 = new Foo { type A = Int }
val e0: SUB[x0.type, Foo { type A = Int }] = SUB.Refl[x0.type]()
def boom(i: Int): String = foo[Nothing, Any](x0, e0, i) : Nothing // cast Int to String! |
671a48c
to
38e6e9e
Compare
9084be9
to
ee3c1e9
Compare
ee3c1e9
to
f42b515
Compare
def tp1IsSingleton: Boolean = tp1.isInstanceOf[SingletonType] | ||
def allowGadt = mbr match | ||
case _ if tp1.isInstanceOf[SingletonType] => false | ||
case d: UniqueRefDenotation if d.prefix == NoPrefix && d.symbol != NoSymbol => false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@odersky this is what I found works. Can you think of another way to identify when we have a member that required widening tp1
to a non-class info and thus we can't safely infer gadt constraints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't make sense of this condition and don't understand the logic behind this. This would at least need a fat comment explaining the issue and the attempted solution.
What is the motivation for these changes? |
#15485 is the issue it fixes (in the sidebar) |
def tp1IsSingleton: Boolean = tp1.isInstanceOf[SingletonType] | ||
def allowGadt = mbr match | ||
case _ if tp1.isInstanceOf[SingletonType] => false | ||
case d: UniqueRefDenotation if d.prefix == NoPrefix && d.symbol != NoSymbol => false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't make sense of this condition and don't understand the logic behind this. This would at least need a fat comment explaining the issue and the attempted solution.
No description provided.