File tree Expand file tree Collapse file tree 5 files changed +72
-1
lines changed
src/dotty/tools/dotc/transform Expand file tree Collapse file tree 5 files changed +72
-1
lines changed Original file line number Diff line number Diff line change @@ -812,7 +812,8 @@ object PatternMatcher {
812812 plan :: Nil
813813 }
814814
815- recur(plan)
815+ if (isSwitchableType(scrutinee.tpe.widen)) recur(plan)
816+ else Nil
816817 }
817818
818819 /** Emit cases of a switch */
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ class CompilationTests extends ParallelTesting {
5555 compileFile(" ../tests/pos-scala2/rewrites.scala" , scala2Mode.and(" -rewrite" )).copyToTarget() +
5656 compileFile(" ../tests/pos-special/utf8encoded.scala" , explicitUTF8) +
5757 compileFile(" ../tests/pos-special/utf16encoded.scala" , explicitUTF16) +
58+ compileFile(" ../tests/pos-special/i3589-b.scala" , defaultOptions.and(" -Xfatal-warnings" )) +
5859 compileList(
5960 " compileMixed" ,
6061 List (
@@ -181,6 +182,7 @@ class CompilationTests extends ParallelTesting {
181182 compileFile(" ../tests/neg-custom-args/overloadsOnAbstractTypes.scala" , allowDoubleBindings) +
182183 compileFile(" ../tests/neg-custom-args/xfatalWarnings.scala" , defaultOptions.and(" -Xfatal-warnings" )) +
183184 compileFile(" ../tests/neg-custom-args/pureStatement.scala" , defaultOptions.and(" -Xfatal-warnings" )) +
185+ compileFile(" ../tests/neg-custom-args/i3589-a.scala" , defaultOptions.and(" -Xfatal-warnings" )) +
184186 compileFile(" ../tests/neg-custom-args/phantom-overload.scala" , allowDoubleBindings) +
185187 compileFile(" ../tests/neg-custom-args/phantom-overload-2.scala" , allowDoubleBindings) +
186188 compileFile(" ../tests/neg-custom-args/structural.scala" , defaultOptions.and(" -Xfatal-warnings" ))
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+ }
Original file line number Diff line number Diff line change 1+ class Foo {
2+ val a : Any = 3
3+ a match {
4+ case 1 =>
5+ case 2 =>
6+ case 3 =>
7+ case _ =>
8+ }
9+ }
10+
11+ class Bar [T ] {
12+ val a : T = ???
13+ a match {
14+ case 1 =>
15+ case 2 =>
16+ case 3 =>
17+ case _ =>
18+ }
19+ }
20+
21+ class Baz {
22+ val a : Double = 1.0
23+ a match {
24+ case 1 =>
25+ case 2 =>
26+ case 3 =>
27+ case _ =>
28+ }
29+ }
30+
31+ class Foo2 {
32+ val a : AnyVal = 3
33+ a match {
34+ case 1 =>
35+ case 2 =>
36+ case 3 =>
37+ case _ =>
38+ }
39+ }
40+
41+
42+ case class A (i : Int ) extends AnyVal
43+ class Foo3 {
44+ val a : A = new A (3 )
45+ a match {
46+ case A (1 ) =>
47+ case A (2 ) =>
48+ case A (3 ) =>
49+ case _ =>
50+ }
51+ }
You can’t perform that action at this time.
0 commit comments