diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index a61bc0cf2a9a..fd000257c75c 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -600,8 +600,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w compareTypeLambda case OrType(tp21, tp22) => if (tp2.atoms.nonEmpty && canCompare(tp2.atoms)) - return tp1.atoms.nonEmpty && tp1.atoms.subsetOf(tp2.atoms) || - tp1.isRef(NothingClass) + return tp1.atoms.nonEmpty && tp1.atoms.subsetOf(tp2.atoms) || isSubType(tp1, NothingType) // The next clause handles a situation like the one encountered in i2745.scala. // We have: diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 36f2d07dbc8c..bea3f53df929 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -1102,8 +1102,11 @@ object Types { } case _ => tp } - Set.empty + normalize(tp) - case tp: OrType => tp.atoms + val underlyingAtoms = tp.underlying.atoms + if (underlyingAtoms.isEmpty) Set.empty + normalize(tp) + else underlyingAtoms + case tp: ExprType => tp.resType.atoms + case tp: OrType => tp.atoms // `atoms` overridden in OrType case tp: AndType => tp.tp1.atoms & tp.tp2.atoms case _ => Set.empty } diff --git a/tests/pos/singlesubtypes.scala b/tests/pos/singlesubtypes.scala new file mode 100644 index 000000000000..bf4273669a02 --- /dev/null +++ b/tests/pos/singlesubtypes.scala @@ -0,0 +1,13 @@ +object E { + val a: String = ??? + val b: String = ??? +} + +object Test { + + val a: E.a.type = E.a + val b: E.b.type = E.b + + val c: a.type | b.type = ??? + val d: a.type | b.type = c +}