Skip to content

Commit f889bf8

Browse files
Don't assume types in & are sorted
1 parent df1bf4d commit f889bf8

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,10 +2005,15 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
20052005
intersecting(tp1.tp1, tp2) || intersecting(tp1.tp2, tp2)
20062006
case (_, tp2: OrType) =>
20072007
intersecting(tp1, tp2.tp1) || intersecting(tp1, tp2.tp2)
2008+
case (tp1: AndType, tp2: AndType) =>
2009+
intersecting(tp1.tp1, tp2.tp1) && intersecting(tp1.tp2, tp2.tp2) ||
2010+
intersecting(tp1.tp1, tp2.tp2) && intersecting(tp1.tp2, tp2.tp1)
20082011
case (tp1: AndType, _) =>
2009-
intersecting(tp1.tp1, tp2) && intersecting(tp1.tp2, tp2) && intersecting(tp1.tp1, tp1.tp2)
2012+
intersecting(tp1.tp1, tp2) && intersecting(tp1.tp2, tp2) ||
2013+
intersecting(tp1.tp2, tp2) && intersecting(tp1.tp1, tp2)
20102014
case (_, tp2: AndType) =>
2011-
intersecting(tp1, tp2.tp1) && intersecting(tp1, tp2.tp2) && intersecting(tp2.tp1, tp2.tp2)
2015+
intersecting(tp1, tp2.tp1) && intersecting(tp1, tp2.tp2) ||
2016+
intersecting(tp1, tp2.tp2) && intersecting(tp1, tp2.tp1)
20122017
case (tp1: TypeProxy, tp2: TypeProxy) =>
20132018
intersecting(tp1.underlying, tp2) && intersecting(tp1, tp2.underlying)
20142019
case (tp1: TypeProxy, _) =>

tests/neg/6314.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object G {
2+
final class X
3+
final class Y
4+
5+
trait Test {
6+
type Type
7+
val i: Bar[Y & Type] = 1 // error
8+
}
9+
10+
type Bar[A] = A match {
11+
case X & Y => String
12+
case Y => Int
13+
}
14+
}

0 commit comments

Comments
 (0)