Skip to content

Commit c0e93f1

Browse files
committed
Disable match anaylsis in inlined trees
1 parent d96e9e4 commit c0e93f1

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ class PatternMatcher extends MiniPhase {
3535

3636
override def runsAfter: Set[String] = Set(ElimRepeated.name)
3737

38+
private val InInlinedCode = new util.Property.Key[Boolean]
39+
private def inInlinedCode(using Context) = ctx.property(InInlinedCode).getOrElse(false)
40+
41+
override def prepareForInlined(tree: Inlined)(using Context): Context =
42+
if inInlinedCode then ctx
43+
else ctx.fresh.setProperty(InInlinedCode, true)
44+
3845
override def transformMatch(tree: Match)(using Context): Tree =
3946
if (tree.isInstanceOf[InlineMatch]) tree
4047
else {
@@ -46,9 +53,10 @@ class PatternMatcher extends MiniPhase {
4653
case rt => tree.tpe
4754
val translated = new Translator(matchType, this).translateMatch(tree)
4855

49-
// check exhaustivity and unreachability
50-
SpaceEngine.checkExhaustivity(tree)
51-
SpaceEngine.checkRedundancy(tree)
56+
if !inInlinedCode then
57+
// check exhaustivity and unreachability
58+
SpaceEngine.checkExhaustivity(tree)
59+
SpaceEngine.checkRedundancy(tree)
5260

5361
translated.ensureConforms(matchType)
5462
}

tests/pos/i19157.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//> using options -Werror
2+
3+
class Test:
4+
inline def count(inline x: Boolean) = x match
5+
case true => 1
6+
case false => 0
7+
8+
assert(count(true) == 1)
9+
assert(count(false) == 0)
10+
var x = true
11+
assert(count(x) == 1)

0 commit comments

Comments
 (0)