Skip to content

Commit

Permalink
Disable match anaylsis in inlined trees
Browse files Browse the repository at this point in the history
[Cherry-picked c0e93f1]
  • Loading branch information
dwijnand authored and WojciechMazur committed Jun 25, 2024
1 parent 0bb1c0a commit bc69ac6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
11 changes: 11 additions & 0 deletions tests/pos/i19157.scala
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit bc69ac6

Please sign in to comment.