Skip to content

Commit e1b8f74

Browse files
authored
Merge pull request #6741 from dotty-staging/fix-subtype-bottom
Fix atoms computation
2 parents 8b1e36a + f94fdda commit e1b8f74

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
600600
compareTypeLambda
601601
case OrType(tp21, tp22) =>
602602
if (tp2.atoms.nonEmpty && canCompare(tp2.atoms))
603-
return tp1.atoms.nonEmpty && tp1.atoms.subsetOf(tp2.atoms) ||
604-
tp1.isRef(NothingClass)
603+
return tp1.atoms.nonEmpty && tp1.atoms.subsetOf(tp2.atoms) || isSubType(tp1, NothingType)
605604

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

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,8 +1102,11 @@ object Types {
11021102
}
11031103
case _ => tp
11041104
}
1105-
Set.empty + normalize(tp)
1106-
case tp: OrType => tp.atoms
1105+
val underlyingAtoms = tp.underlying.atoms
1106+
if (underlyingAtoms.isEmpty) Set.empty + normalize(tp)
1107+
else underlyingAtoms
1108+
case tp: ExprType => tp.resType.atoms
1109+
case tp: OrType => tp.atoms // `atoms` overridden in OrType
11071110
case tp: AndType => tp.tp1.atoms & tp.tp2.atoms
11081111
case _ => Set.empty
11091112
}

tests/pos/singlesubtypes.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
val d: a.type | b.type = c
13+
}

0 commit comments

Comments
 (0)