File tree Expand file tree Collapse file tree 4 files changed +28
-3
lines changed
src/dotty/tools/dotc/transform Expand file tree Collapse file tree 4 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -791,6 +791,12 @@ object PatternMatcher {
791
791
* plan and following onSuccess plans.
792
792
*/
793
793
private def collectSwitchCases (plan : TestPlan ): List [Plan ] = {
794
+ def isSwitchableType (tpe : Type ): Boolean =
795
+ (tpe isRef defn.IntClass ) ||
796
+ (tpe isRef defn.ByteClass ) ||
797
+ (tpe isRef defn.ShortClass ) ||
798
+ (tpe isRef defn.CharClass )
799
+
794
800
val scrutinee = plan.scrutinee
795
801
796
802
def isIntConst (tree : Tree ) = tree match {
@@ -805,9 +811,9 @@ object PatternMatcher {
805
811
case _ =>
806
812
plan :: Nil
807
813
}
808
- val cls = scrutinee.tpe.widen.classSymbol
809
- if (cls == defn. AnyClass || cls == defn. AnyValClass ) Nil
810
- else recur(plan)
814
+
815
+ if (isSwitchableType(scrutinee.tpe.widen)) recur(plan)
816
+ else Nil
811
817
}
812
818
813
819
/** Emit cases of a switch */
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ class CompilationTests extends ParallelTesting {
55
55
compileFile(" ../tests/pos-scala2/rewrites.scala" , scala2Mode.and(" -rewrite" )).copyToTarget() +
56
56
compileFile(" ../tests/pos-special/utf8encoded.scala" , explicitUTF8) +
57
57
compileFile(" ../tests/pos-special/utf16encoded.scala" , explicitUTF16) +
58
+ compileFile(" ../tests/pos-special/i3589-b.scala" , defaultOptions.and(" -Xfatal-warnings" )) +
58
59
compileList(
59
60
" compileMixed" ,
60
61
List (
@@ -179,6 +180,7 @@ class CompilationTests extends ParallelTesting {
179
180
compileFile(" ../tests/neg/customArgs/overloadsOnAbstractTypes.scala" , allowDoubleBindings) +
180
181
compileFile(" ../tests/neg/customArgs/xfatalWarnings.scala" , defaultOptions.and(" -Xfatal-warnings" )) +
181
182
compileFile(" ../tests/neg/customArgs/pureStatement.scala" , defaultOptions.and(" -Xfatal-warnings" )) +
183
+ compileFile(" ../tests/neg/customArgs/i3589-a.scala" , defaultOptions.and(" -Xfatal-warnings" )) +
182
184
compileFile(" ../tests/neg/customArgs/phantom-overload.scala" , allowDoubleBindings) +
183
185
compileFile(" ../tests/neg/customArgs/phantom-overload-2.scala" , allowDoubleBindings) +
184
186
compileFile(" ../tests/neg/tailcall/t1672b.scala" , defaultOptions) +
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ case class IntAnyVal (x : Int ) extends AnyVal
3
+
4
+ def test (x : IntAnyVal ) = (x : @ annotation.switch) match { // error: warning: could not emit switch
5
+ case IntAnyVal (1 ) => 1
6
+ case IntAnyVal (2 ) => 2
7
+ case IntAnyVal (3 ) => 3
8
+ case _ => 4
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ class Test {
2
+ def test (x : 1 ) = (x : @ annotation.switch) match {
3
+ case 1 => 1
4
+ case 2 => 2
5
+ case 3 => 3
6
+ }
7
+ }
You can’t perform that action at this time.
0 commit comments