Skip to content
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

Fix #6314: match type unsoundness #6319

Merged
merged 11 commits into from
May 17, 2019
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2005,10 +2005,15 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
intersecting(tp1.tp1, tp2) || intersecting(tp1.tp2, tp2)
case (_, tp2: OrType) =>
intersecting(tp1, tp2.tp1) || intersecting(tp1, tp2.tp2)
case (tp1: AndType, tp2: AndType) =>
intersecting(tp1.tp1, tp2.tp1) && intersecting(tp1.tp2, tp2.tp2) ||
intersecting(tp1.tp1, tp2.tp2) && intersecting(tp1.tp2, tp2.tp1)
case (tp1: AndType, _) =>
intersecting(tp1.tp1, tp2) && intersecting(tp1.tp2, tp2) && intersecting(tp1.tp1, tp1.tp2)
intersecting(tp1.tp1, tp2) && intersecting(tp1.tp2, tp2) ||
OlivierBlanvillain marked this conversation as resolved.
Show resolved Hide resolved
intersecting(tp1.tp2, tp2) && intersecting(tp1.tp1, tp2)
case (_, tp2: AndType) =>
intersecting(tp1, tp2.tp1) && intersecting(tp1, tp2.tp2) && intersecting(tp2.tp1, tp2.tp2)
intersecting(tp1, tp2.tp1) && intersecting(tp1, tp2.tp2) ||
OlivierBlanvillain marked this conversation as resolved.
Show resolved Hide resolved
intersecting(tp1, tp2.tp2) && intersecting(tp1, tp2.tp1)
case (tp1: TypeProxy, tp2: TypeProxy) =>
intersecting(tp1.underlying, tp2) && intersecting(tp1, tp2.underlying)
case (tp1: TypeProxy, _) =>
Expand Down
14 changes: 14 additions & 0 deletions tests/neg/6314.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
object G {
final class X
final class Y

trait Test {
type Type
val i: Bar[Y & Type] = 1 // error
}

type Bar[A] = A match {
case X & Y => String
case Y => Int
}
}