Skip to content

Commit 49fc004

Browse files
committed
Fix #9016: Fix stackoverflows in provablyDisjoint
1 parent 38272aa commit 49fc004

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,9 +2417,11 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
24172417
(provablyDisjoint(tp1.tp1, tp2.tp1) || provablyDisjoint(tp1.tp2, tp2.tp2)) &&
24182418
(provablyDisjoint(tp1.tp1, tp2.tp2) || provablyDisjoint(tp1.tp2, tp2.tp1))
24192419
case (tp1: AndType, _) =>
2420-
provablyDisjoint(tp1.tp2, tp2) || provablyDisjoint(tp1.tp1, tp2)
2420+
!(tp1 <:< tp2)
2421+
&& (provablyDisjoint(tp1.tp2, tp2) || provablyDisjoint(tp1.tp1, tp2))
24212422
case (_, tp2: AndType) =>
2422-
provablyDisjoint(tp1, tp2.tp2) || provablyDisjoint(tp1, tp2.tp1)
2423+
!(tp2 <:< tp1)
2424+
&& (provablyDisjoint(tp1, tp2.tp2) || provablyDisjoint(tp1, tp2.tp1))
24232425
case (tp1: TypeProxy, tp2: TypeProxy) =>
24242426
provablyDisjoint(tp1.underlying, tp2) || provablyDisjoint(tp1, tp2.underlying)
24252427
case (tp1: TypeProxy, _) =>

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)