File tree 4 files changed +26
-1
lines changed
compiler/src/dotty/tools/dotc/transform
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 {
56
56
if ! inInlinedCode then
57
57
// check exhaustivity and unreachability
58
58
SpaceEngine .checkMatch(tree)
59
+ else
60
+ // only check exhaustivity, as inlining may generate unreachable code
61
+ // like in i19157.scala
62
+ SpaceEngine .checkMatchExhaustivityOnly(tree)
59
63
60
64
translated.ensureConforms(matchType)
61
65
}
Original file line number Diff line number Diff line change @@ -901,6 +901,9 @@ object SpaceEngine {
901
901
}
902
902
903
903
def checkMatch (m : Match )(using Context ): Unit =
904
- if exhaustivityCheckable(m.selector) then checkExhaustivity (m)
904
+ checkMatchExhaustivityOnly (m)
905
905
if reachabilityCheckable(m.selector) then checkReachability(m)
906
+
907
+ def checkMatchExhaustivityOnly (m : Match )(using Context ): Unit =
908
+ if exhaustivityCheckable(m.selector) then checkExhaustivity(m)
906
909
}
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