File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments