Skip to content

Commit ea04343

Browse files
Update inhabited check in Space
To be more conservative during the traversal. As pointed out in the review "nested non-inhabitable intersection type does not necessarily mean the outer type is non-inhabited".
1 parent f4df58d commit ea04343

File tree

1 file changed

+10
-9
lines changed
  • compiler/src/dotty/tools/dotc/transform/patmat

1 file changed

+10
-9
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -468,16 +468,17 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
468468
val parts = children.map { sym =>
469469
val sym1 = if (sym.is(ModuleClass)) sym.sourceModule else sym
470470
val refined = ctx.refineUsingParent(tp, sym1)
471-
val inhabited = new TypeAccumulator[Boolean] {
472-
override def apply(x: Boolean, tp: Type) = x && {
473-
tp match {
474-
case AndType(tp1, tp2) => ctx.typeComparer.intersecting(tp1, tp2)
475-
case OrType(tp1, tp2) => foldOver(x, tp1) || foldOver(x, tp2)
476-
case _ => foldOver(x, tp)
477-
}
471+
472+
def inhabited(tp: Type): Boolean =
473+
tp.dealias match {
474+
case AndType(tp1, tp2) => ctx.typeComparer.intersecting(tp1, tp2)
475+
case OrType(tp1, tp2) => inhabited(tp1) || inhabited(tp2)
476+
case tp: RefinedType => inhabited(tp.parent)
477+
case tp: TypeRef => inhabited(tp.prefix)
478+
case _ => true
478479
}
479-
}
480-
if (inhabited.apply(true, refined)) refined
480+
481+
if (inhabited(refined)) refined
481482
else NoType
482483
} filter(_.exists)
483484

0 commit comments

Comments
 (0)