Skip to content

Commit f28b9c1

Browse files
committed
Move reachability skip to reachabilityCheckable
1 parent f3b58cf commit f28b9c1

File tree

9 files changed

+32
-42
lines changed

9 files changed

+32
-42
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,10 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
385385
runPhases(allPhases = fusedPhases)(using runCtx)
386386
cancelAsyncTasty()
387387

388+
ctx.reporter.finalizeReporting()
388389
if (!ctx.reporter.hasErrors)
389390
Rewrites.writeBack()
390391
suppressions.runFinished(hasErrors = ctx.reporter.hasErrors)
391-
ctx.reporter.finalizeReporting()
392392
while (finalizeActions.nonEmpty && canProgress()) {
393393
val action = finalizeActions.remove(0)
394394
action()

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,8 @@ class PatternMatcher extends MiniPhase {
4646
case rt => tree.tpe
4747
val translated = new Translator(matchType, this).translateMatch(tree)
4848

49-
// Skip unreachability analysis on inlined code (eg pos/i19157)
50-
if !tpd.enclosingInlineds.nonEmpty then
51-
// check exhaustivity and unreachability
52-
SpaceEngine.checkMatch(tree)
53-
else
54-
// only check exhaustivity
55-
SpaceEngine.checkMatchExhaustivityOnly(tree)
49+
// check exhaustivity and unreachability
50+
SpaceEngine.checkMatch(tree)
5651

5752
translated.ensureConforms(matchType)
5853
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ object SpaceEngine {
922922
!sel.tpe.hasAnnotation(defn.UncheckedAnnot)
923923
&& !sel.tpe.widen.isRef(defn.QuotedExprClass)
924924
&& !sel.tpe.widen.isRef(defn.QuotedTypeClass)
925+
&& tpd.enclosingInlineds.isEmpty // Skip reachability on inlined code (eg i19157/i22212)
925926

926927
def checkReachability(m: Match)(using Context): Unit = trace(i"checkReachability($m)"):
927928
val selTyp = toUnderlying(m.selector.tpe).dealias
@@ -972,10 +973,6 @@ object SpaceEngine {
972973
end checkReachability
973974

974975
def checkMatch(m: Match)(using Context): Unit =
975-
checkMatchExhaustivityOnly(m)
976-
if reachabilityCheckable(m.selector) then checkReachability(m)
977-
978-
def checkMatchExhaustivityOnly(m: Match)(using Context): Unit =
979976
if exhaustivityCheckable(m.selector) then checkExhaustivity(m)
980-
977+
if reachabilityCheckable(m.selector) then checkReachability(m)
981978
}

tests/neg-macros/i22212.check

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/neg-macros/i22212/Test_2.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/warn/i22212.check

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
-- [E029] Pattern Match Exhaustivity Warning: tests/warn/i22212/Test_2.scala:3:19 --------------------------------------
3+
3 | Macro.makeMatch() // warn: match may not be exhaustive.
4+
| ^^^^^^^^^^^^^^^^^
5+
| match may not be exhaustive.
6+
|
7+
| It would fail on pattern case: Baz
8+
|---------------------------------------------------------------------------------------------------------------------
9+
|Inline stack trace
10+
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
11+
|This location contains code that was inlined from Macro_1.scala:7
12+
7 | (_: Foo) match
13+
| ^^^^^^
14+
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15+
|This location contains code that was inlined from Macro_1.scala:7
16+
7 | (_: Foo) match
17+
| ^
18+
8 | case Bar => ()
19+
---------------------------------------------------------------------------------------------------------------------
20+
|
21+
| longer explanation available when compiling with `-explain`

tests/warn/i22212/Data_1.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sealed trait Foo
2+
case object Bar extends Foo
3+
case object Baz extends Foo

tests/neg-macros/i22212/Macro_1.scala renamed to tests/warn/i22212/Macro_1.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import scala.quoted._
22

3-
sealed trait Foo
4-
case object Bar extends Foo
5-
case object Baz extends Foo
6-
73
object Macro {
84
inline def makeMatch() = ${makeMatchImpl}
95
def makeMatchImpl(using Quotes) = {

tests/warn/i22212/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test:
2+
def main(args: Array[String]): Unit =
3+
Macro.makeMatch() // warn: match may not be exhaustive.

0 commit comments

Comments
 (0)