File tree 4 files changed +8
-8
lines changed
compiler/src/dotty/tools/dotc
tests/neg-custom-args/fatal-warnings
4 files changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -1969,10 +1969,9 @@ import ast.tpd
1969
1969
|whose behavior may have changed since version change. """
1970
1970
}
1971
1971
1972
- class UnableToEmitSwitch (tooFewCases : Boolean )(using Context )
1972
+ class UnableToEmitSwitch ()(using Context )
1973
1973
extends SyntaxMsg (UnableToEmitSwitchID ) {
1974
- def tooFewStr : String = if (tooFewCases) " since there are not enough cases" else " "
1975
- def msg = em " Could not emit switch for ${hl(" @switch" )} annotated match $tooFewStr"
1974
+ def msg = em " Could not emit switch for ${hl(" @switch" )} annotated match "
1976
1975
def explain = {
1977
1976
val codeExample =
1978
1977
""" val ConstantB = 'B'
Original file line number Diff line number Diff line change @@ -983,12 +983,13 @@ object PatternMatcher {
983
983
cdefs.flatMap(cdef => typesInPattern(cdef.pat))
984
984
def numTypes (cdefs : List [CaseDef ]): Int =
985
985
typesInCases(cdefs).toSet.size: Int // without the type ascription, testPickling fails because of #2840.
986
- if (numTypes(resultCases) < numTypes(original.cases)) {
986
+ if (numTypes(resultCases) < numTypes(original.cases)
987
+ && numTypes(original.cases) >= MinSwitchCases ) {
987
988
patmatch.println(i " switch warning for ${ctx.compilationUnit}" )
988
989
patmatch.println(i " original types: ${typesInCases(original.cases)}%, % " )
989
990
patmatch.println(i " switch types : ${typesInCases(resultCases)}%, % " )
990
991
patmatch.println(i " tree = $result" )
991
- report.warning(UnableToEmitSwitch (numTypes(original.cases) < MinSwitchCases ), original.srcPos)
992
+ report.warning(UnableToEmitSwitch (), original.srcPos)
992
993
}
993
994
case _ =>
994
995
}
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ class Test {
14
14
case '4' => 4
15
15
}
16
16
17
- def test3 (x : Any ) = (x : @ annotation.switch) match { // error: could not emit switch - too few cases
17
+ def test3 (x : Any ) = (x : @ annotation.switch) match {
18
18
case 1 => 1
19
19
case 2 => 2
20
20
case x : String => 4
Original file line number Diff line number Diff line change @@ -36,14 +36,14 @@ object Main {
36
36
// multiple annotations are processed correctly
37
37
38
38
// thinks a val in an object is constant... so naive
39
- def fail1 (c : Char ) = (c : @ switch @ unchecked) match { // error: Could not emit switch for @switch annotated match
39
+ def fail1 (c : Char ) = (c : @ switch @ unchecked) match {
40
40
case 'A' => true
41
41
case Other .C1 => true
42
42
case _ => false
43
43
}
44
44
45
45
// more naivete
46
- def fail2 (c : Char ) = (c : @ unchecked @ switch) match { // error: Could not emit switch for @switch annotated match
46
+ def fail2 (c : Char ) = (c : @ unchecked @ switch) match {
47
47
case 'A' => true
48
48
case Other .C3 => true
49
49
case _ => false
You can’t perform that action at this time.
0 commit comments