Skip to content

Commit a945326

Browse files
committed
Tweak reachability to only warn after the first reachable case
In the event that the first case is unreachable, the logic descended to `isSubspace(covered, prevs)` where both are the Empty Space, emitting warnings. Instead we implement reachability like the Scala 2 compiler defines it: // a case is unreachable if it implies its preceding cases
1 parent 5fb2ac0 commit a945326

File tree

1 file changed

+7
-4
lines changed
  • compiler/src/dotty/tools/dotc/transform/patmat

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -922,10 +922,13 @@ class SpaceEngine(using Context) extends SpaceLogic {
922922

923923
(1 until cases.length).foreach { i =>
924924
val pat = cases(i).pat
925-
926-
if (pat != EmptyTree) { // rethrow case of catch uses EmptyTree
927-
val prevs = Or(spaces.take(i))
928-
val curr = project(pat)
925+
val prevs = Or(spaces.take(i))
926+
if (pat != EmptyTree // rethrow case of catch uses EmptyTree
927+
&& simplify(intersect(prevs, targetSpace)) != Empty
928+
// it's required that at one of the previous cases is reachable (its intersected Space isn't Empty)
929+
// because if all the previous cases are unreachable then case i can't be unreachable
930+
) {
931+
val curr = project(pat) // TODO(dnw) reuse `spaces(i)` & avoid re-computing? Or is mutability present?
929932

930933
debug.println(s"---------------reachable? ${show(curr)}")
931934
debug.println(s"prev: ${show(prevs)}")

0 commit comments

Comments
 (0)