Skip to content

Commit 047a449

Browse files
committed
Avoid infinite recursion when comparing Nothing and union types
1 parent 866ac14 commit 047a449

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
601601
case OrType(tp21, tp22) =>
602602
if (tp2.atoms.nonEmpty && canCompare(tp2.atoms))
603603
return tp1.atoms.nonEmpty && tp1.atoms.subsetOf(tp2.atoms) ||
604-
tp1.isRef(NothingClass)
604+
tp1.widen.isRef(NothingClass)
605605

606606
// The next clause handles a situation like the one encountered in i2745.scala.
607607
// We have:

tests/pos/singlesubtypes.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object E {
2+
val a: String = ???
3+
val b: String = ???
4+
}
5+
6+
object Test {
7+
8+
val a: E.a.type = E.a
9+
val b: E.b.type = E.b
10+
11+
val c: a.type | b.type = ???
12+
}

0 commit comments

Comments
 (0)