Skip to content

Commit 484e3c6

Browse files
Merge pull request #9017 from dotty-staging/fix-#9011
Fix #9016: Fix stackoverflows in provablyDisjoint
2 parents 94494ff + 157ad25 commit 484e3c6

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,13 +2413,12 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
24132413
provablyDisjoint(tp1.tp1, tp2) && provablyDisjoint(tp1.tp2, tp2)
24142414
case (_, tp2: OrType) =>
24152415
provablyDisjoint(tp1, tp2.tp1) && provablyDisjoint(tp1, tp2.tp2)
2416-
case (tp1: AndType, tp2: AndType) =>
2417-
(provablyDisjoint(tp1.tp1, tp2.tp1) || provablyDisjoint(tp1.tp2, tp2.tp2)) &&
2418-
(provablyDisjoint(tp1.tp1, tp2.tp2) || provablyDisjoint(tp1.tp2, tp2.tp1))
24192416
case (tp1: AndType, _) =>
2420-
provablyDisjoint(tp1.tp2, tp2) || provablyDisjoint(tp1.tp1, tp2)
2417+
!(tp1 <:< tp2)
2418+
&& (provablyDisjoint(tp1.tp2, tp2) || provablyDisjoint(tp1.tp1, tp2))
24212419
case (_, tp2: AndType) =>
2422-
provablyDisjoint(tp1, tp2.tp2) || provablyDisjoint(tp1, tp2.tp1)
2420+
!(tp2 <:< tp1)
2421+
&& (provablyDisjoint(tp1, tp2.tp2) || provablyDisjoint(tp1, tp2.tp1))
24232422
case (tp1: TypeProxy, tp2: TypeProxy) =>
24242423
provablyDisjoint(tp1.underlying, tp2) || provablyDisjoint(tp1, tp2.underlying)
24252424
case (tp1: TypeProxy, _) =>

tests/patmat/andtype-opentype-interaction.check

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
27: Pattern Match Exhaustivity: _: Trait & OpenTrait & OpenTrait2, _: Clazz & OpenTrait & OpenTrait2, _: AbstractClass & OpenTrait & OpenTrait2, _: SealedClass & OpenTrait & OpenTrait2
33
31: Pattern Match Exhaustivity: _: Trait & OpenClass
44
35: Pattern Match Exhaustivity: _: Trait & OpenTrait & OpenClass
5-
39: Pattern Match Exhaustivity: _: Trait & OpenClass & (OpenTrait & OpenClass2)
65
43: Pattern Match Exhaustivity: _: Trait & OpenAbstractClass
76
47: Pattern Match Exhaustivity: _: Trait & OpenClass & (OpenTrait & OpenClassSubclass)

tests/patmat/andtype-opentype-interaction.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object Test {
3737
}
3838

3939
def m2c(s: (T & OpenClass) & (OpenTrait & OpenClass2)) = s match {
40-
case _: Unrelated => ;
40+
case _: Unrelated => ; // OK since scrutinee is the empty type
4141
}
4242

4343
def m3(s: T & OpenAbstractClass) = s match {

tests/run/enum-Tree.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
trait P
12
enum Tree[T] {
2-
case True extends Tree[Boolean]
3-
case False extends Tree[Boolean]
4-
case Zero extends Tree[Int]
5-
case Succ(n: Tree[Int]) extends Tree[Int]
6-
case Pred(n: Tree[Int]) extends Tree[Int]
7-
case IsZero(n: Tree[Int]) extends Tree[Boolean]
3+
case True extends Tree[Boolean], P
4+
case False extends Tree[Boolean], P
5+
case Zero extends Tree[Int], P
6+
case Succ(n: Tree[Int]) extends Tree[Int], P
7+
case Pred(n: Tree[Int]) extends Tree[Int], P
8+
case IsZero(n: Tree[Int]) extends Tree[Boolean], P
89
case If(cond: Tree[Boolean], thenp: Tree[T], elsep: Tree[T])
9-
extends Tree[T]
10+
extends Tree[T], P
1011
}
1112

1213
object Test {

0 commit comments

Comments
 (0)