File tree Expand file tree Collapse file tree 4 files changed +26
-1
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 4 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,10 @@ class PatternMatcher extends MiniPhase {
5656 if ! inInlinedCode then
5757 // check exhaustivity and unreachability
5858 SpaceEngine .checkMatch(tree)
59+ else
60+ // only check exhaustivity, as inlining may generate unreachable code
61+ // like in i19157.scala
62+ SpaceEngine .checkMatchExhaustivityOnly(tree)
5963
6064 translated.ensureConforms(matchType)
6165 }
Original file line number Diff line number Diff line change @@ -901,6 +901,9 @@ object SpaceEngine {
901901 }
902902
903903 def checkMatch (m : Match )(using Context ): Unit =
904- if exhaustivityCheckable(m.selector) then checkExhaustivity (m)
904+ checkMatchExhaustivityOnly (m)
905905 if reachabilityCheckable(m.selector) then checkReachability(m)
906+
907+ def checkMatchExhaustivityOnly (m : Match )(using Context ): Unit =
908+ if exhaustivityCheckable(m.selector) then checkExhaustivity(m)
906909}
Original file line number Diff line number Diff line change 1+ -- [E029] Pattern Match Exhaustivity Warning: tests/warn/i20372.scala:8:5 ----------------------------------------------
2+ 8 | id(foo match { // warn
3+ | ^^^
4+ | match may not be exhaustive.
5+ |
6+ | It would fail on pattern case: Baz
7+ |
8+ | longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change 1+ sealed trait Foo
2+ case object Bar extends Foo
3+ case object Baz extends Foo
4+
5+ inline def id [A ](a : A ): A = a
6+
7+ def shouldThrowAWarning (foo : Foo ) =
8+ id(foo match { // warn
9+ case Bar => " Bar"
10+ })
You can’t perform that action at this time.
0 commit comments