File tree 2 files changed +22
-3
lines changed
compiler/src/dotty/tools/dotc/transform
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 {
35
35
36
36
override def runsAfter : Set [String ] = Set (ElimRepeated .name)
37
37
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
+
38
45
override def transformMatch (tree : Match )(using Context ): Tree =
39
46
if (tree.isInstanceOf [InlineMatch ]) tree
40
47
else {
@@ -46,9 +53,10 @@ class PatternMatcher extends MiniPhase {
46
53
case rt => tree.tpe
47
54
val translated = new Translator (matchType, this ).translateMatch(tree)
48
55
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)
52
60
53
61
translated.ensureConforms(matchType)
54
62
}
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