File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -969,11 +969,15 @@ object PatternMatcher {
969
969
case Block (_, Match (_, cases)) => cases
970
970
case _ => Nil
971
971
}
972
- def numConsts (cdefs : List [CaseDef ]): Int = {
973
- val tpes = cdefs.map(_.pat.tpe)
974
- tpes.toSet.size
972
+ def numTypes (cdefs : List [CaseDef ]): Int = {
973
+ def patTypes (pat : Tree ): List [Type ] = pat match {
974
+ case Alternative (pats) => pats.flatMap(patTypes)
975
+ case _ => pat.tpe :: Nil
976
+ }
977
+ val tpes = cdefs.flatMap(patTypes)
978
+ tpes.toSet.size: Int // without the type ascription, testPickling fails because of #2840.
975
979
}
976
- if (numConsts (resultCases) < numConsts (original.cases))
980
+ if (numTypes (resultCases) < numTypes (original.cases))
977
981
ctx.warning(UnableToEmitSwitch (), original.pos)
978
982
case _ =>
979
983
}
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