diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala index ee608a4297bf..250d4844d2b3 100644 --- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -46,10 +46,8 @@ class PatternMatcher extends MiniPhase { case rt => tree.tpe val translated = new Translator(matchType, this).translateMatch(tree) - // Skip analysis on inlined code (eg pos/i19157) - if !tpd.enclosingInlineds.nonEmpty then - // check exhaustivity and unreachability - SpaceEngine.checkMatch(tree) + // check exhaustivity and unreachability + SpaceEngine.checkMatch(tree) translated.ensureConforms(matchType) } diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 612b1e06f1c6..8ab5c93b1d68 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -922,6 +922,7 @@ object SpaceEngine { !sel.tpe.hasAnnotation(defn.UncheckedAnnot) && !sel.tpe.widen.isRef(defn.QuotedExprClass) && !sel.tpe.widen.isRef(defn.QuotedTypeClass) + && tpd.enclosingInlineds.isEmpty // Skip reachability on inlined code (eg i19157/i22212) def checkReachability(m: Match)(using Context): Unit = trace(i"checkReachability($m)"): val selTyp = toUnderlying(m.selector.tpe).dealias diff --git a/tests/warn/i22212.check b/tests/warn/i22212.check new file mode 100644 index 000000000000..d81ec1ffeff8 --- /dev/null +++ b/tests/warn/i22212.check @@ -0,0 +1,21 @@ + +-- [E029] Pattern Match Exhaustivity Warning: tests/warn/i22212/Test_2.scala:3:19 -------------------------------------- +3 | Macro.makeMatch() // warn: match may not be exhaustive. + | ^^^^^^^^^^^^^^^^^ + | match may not be exhaustive. + | + | It would fail on pattern case: Baz + |--------------------------------------------------------------------------------------------------------------------- + |Inline stack trace + |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + |This location contains code that was inlined from Macro_1.scala:7 +7 | (_: Foo) match + | ^^^^^^ + |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + |This location contains code that was inlined from Macro_1.scala:7 +7 | (_: Foo) match + | ^ +8 | case Bar => () + --------------------------------------------------------------------------------------------------------------------- + | + | longer explanation available when compiling with `-explain` diff --git a/tests/warn/i22212/Data_1.scala b/tests/warn/i22212/Data_1.scala new file mode 100644 index 000000000000..1f14d9e2d3eb --- /dev/null +++ b/tests/warn/i22212/Data_1.scala @@ -0,0 +1,3 @@ +sealed trait Foo +case object Bar extends Foo +case object Baz extends Foo diff --git a/tests/warn/i22212/Macro_1.scala b/tests/warn/i22212/Macro_1.scala new file mode 100644 index 000000000000..9fcd9a2273ac --- /dev/null +++ b/tests/warn/i22212/Macro_1.scala @@ -0,0 +1,11 @@ +import scala.quoted._ + +object Macro { + inline def makeMatch() = ${makeMatchImpl} + def makeMatchImpl(using Quotes) = { + '{ + (_: Foo) match + case Bar => () + } + } +} diff --git a/tests/warn/i22212/Test_2.scala b/tests/warn/i22212/Test_2.scala new file mode 100644 index 000000000000..8990a85ff066 --- /dev/null +++ b/tests/warn/i22212/Test_2.scala @@ -0,0 +1,3 @@ +object Test: + def main(args: Array[String]): Unit = + Macro.makeMatch() // warn: match may not be exhaustive.