File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -967,11 +967,15 @@ object PatternMatcher {
967
967
case Block (_, Match (_, cases)) => cases
968
968
case _ => Nil
969
969
}
970
- def numConsts (cdefs : List [CaseDef ]): Int = {
971
- val tpes = cdefs.map(_.pat.tpe)
970
+ def numTypes (cdefs : List [CaseDef ]): Int = {
971
+ def patTypes (pat : Tree ): List [Type ] = pat match {
972
+ case Alternative (pats) => pats.flatMap(patTypes)
973
+ case _ => pat.tpe :: Nil
974
+ }
975
+ val tpes = cdefs.flatMap(patTypes)
972
976
tpes.toSet.size: Int // without the type ascription, testPickling fails because of #2840.
973
977
}
974
- if (numConsts (resultCases) < numConsts (original.cases))
978
+ if (numTypes (resultCases) < numTypes (original.cases))
975
979
ctx.warning(UnableToEmitSwitch (), original.pos)
976
980
case _ =>
977
981
}
Original file line number Diff line number Diff line change
1
+ class Test {
2
+ val Constant = 'Q' // OK if final
3
+ def tokenMe (ch : Char ) = (ch : @ annotation.switch) match { // error: could not emit switch
4
+ case ' ' => 1
5
+ case 'A' => 2
6
+ case '5' | Constant => 3
7
+ case '4' => 4
8
+ }
9
+
10
+ def test2 (x : Any ) = (x : @ annotation.switch) match { // error: could not emit switch
11
+ case ' ' => 1
12
+ case 'A' => 2
13
+ case '5' | Constant => 3
14
+ case '4' => 4
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments