From c0e93f1a57185ffebc0acdd61a54512e688976eb Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 4 Dec 2023 16:29:08 +0000 Subject: [PATCH] Disable match anaylsis in inlined trees --- .../tools/dotc/transform/PatternMatcher.scala | 14 +++++++++++--- tests/pos/i19157.scala | 11 +++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i19157.scala diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala index f6d15b65b9f6..a73bd0841957 100644 --- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -35,6 +35,13 @@ class PatternMatcher extends MiniPhase { override def runsAfter: Set[String] = Set(ElimRepeated.name) + private val InInlinedCode = new util.Property.Key[Boolean] + private def inInlinedCode(using Context) = ctx.property(InInlinedCode).getOrElse(false) + + override def prepareForInlined(tree: Inlined)(using Context): Context = + if inInlinedCode then ctx + else ctx.fresh.setProperty(InInlinedCode, true) + override def transformMatch(tree: Match)(using Context): Tree = if (tree.isInstanceOf[InlineMatch]) tree else { @@ -46,9 +53,10 @@ class PatternMatcher extends MiniPhase { case rt => tree.tpe val translated = new Translator(matchType, this).translateMatch(tree) - // check exhaustivity and unreachability - SpaceEngine.checkExhaustivity(tree) - SpaceEngine.checkRedundancy(tree) + if !inInlinedCode then + // check exhaustivity and unreachability + SpaceEngine.checkExhaustivity(tree) + SpaceEngine.checkRedundancy(tree) translated.ensureConforms(matchType) } diff --git a/tests/pos/i19157.scala b/tests/pos/i19157.scala new file mode 100644 index 000000000000..019403adba73 --- /dev/null +++ b/tests/pos/i19157.scala @@ -0,0 +1,11 @@ +//> using options -Werror + +class Test: + inline def count(inline x: Boolean) = x match + case true => 1 + case false => 0 + + assert(count(true) == 1) + assert(count(false) == 0) + var x = true + assert(count(x) == 1)