Skip to content

Commit 0c26ce1

Browse files
committed
Move checkMatch into SpaceEngine
... makes it easier to disable one of them.
1 parent a825f9b commit 0c26ce1

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ class PatternMatcher extends MiniPhase {
5555

5656
if !inInlinedCode then
5757
// check exhaustivity and unreachability
58-
SpaceEngine.checkExhaustivity(tree)
59-
SpaceEngine.checkRedundancy(tree)
58+
SpaceEngine.checkMatch(tree)
6059

6160
translated.ensureConforms(matchType)
6261
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ object SpaceEngine {
876876
case _ => tp
877877
})
878878

879-
def checkExhaustivity(m: Match)(using Context): Unit = if exhaustivityCheckable(m.selector) then trace(i"checkExhaustivity($m)", debug) {
879+
def checkExhaustivity(m: Match)(using Context): Unit = trace(i"checkExhaustivity($m)", debug) {
880880
val selTyp = toUnderlying(m.selector.tpe).dealias
881881
debug.println(i"selTyp = $selTyp")
882882

@@ -899,7 +899,7 @@ object SpaceEngine {
899899
report.warning(PatternMatchExhaustivity(showSpaces(deduped), m), m.selector)
900900
}
901901

902-
private def redundancyCheckable(sel: Tree)(using Context): Boolean =
902+
private def reachabilityCheckable(sel: Tree)(using Context): Boolean =
903903
// Ignore Expr[T] and Type[T] for unreachability as a special case.
904904
// Quote patterns produce repeated calls to the same unapply method, but with different implicit parameters.
905905
// Since we assume that repeated calls to the same unapply method overlap
@@ -909,7 +909,7 @@ object SpaceEngine {
909909
&& !sel.tpe.widen.isRef(defn.QuotedExprClass)
910910
&& !sel.tpe.widen.isRef(defn.QuotedTypeClass)
911911

912-
def checkRedundancy(m: Match)(using Context): Unit = if redundancyCheckable(m.selector) then trace(i"checkRedundancy($m)", debug) {
912+
def checkReachability(m: Match)(using Context): Unit = trace(i"checkReachability($m)", debug) {
913913
val cases = m.cases.toIndexedSeq
914914

915915
val selTyp = toUnderlying(m.selector.tpe).dealias
@@ -961,4 +961,10 @@ object SpaceEngine {
961961
i += 1
962962
}
963963
}
964+
965+
def checkMatch(m: Match)(using Context): Unit =
966+
if exhaustivityCheckable(m.selector) then
967+
checkExhaustivity(m)
968+
if reachabilityCheckable(m.selector) then
969+
checkReachability(m)
964970
}

0 commit comments

Comments
 (0)