Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)