Skip to content

Commit 8d0e9e0

Browse files
Check inhabitation of children in Space
1 parent 2f86033 commit 8d0e9e0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,18 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
467467
case tp =>
468468
val parts = children.map { sym =>
469469
val sym1 = if (sym.is(ModuleClass)) sym.sourceModule else sym
470-
ctx.typer.refineUsingParent(tp, sym1)
470+
val refined = ctx.typer.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+
}
478+
}
479+
}
480+
if (inhabited.apply(true, refined)) refined
481+
else NoType
471482
} filter(_.exists)
472483

473484
debug.println(s"${tp.show} decomposes to [${parts.map(_.show).mkString(", ")}]")
@@ -735,7 +746,6 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
735746
ctx.warning(MatchCaseOnlyNullWarning(), pat.sourcePos)
736747
case _ =>
737748
}
738-
739749
}
740750
}
741751
}
File renamed without changes.

0 commit comments

Comments
 (0)