Skip to content

Commit 00dc76d

Browse files
committed
Fix #3588: Do not emit switch when matching on non switchable types
1 parent 068f42d commit 00dc76d

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,8 @@ object PatternMatcher {
811811
case _ =>
812812
plan :: Nil
813813
}
814-
815-
recur(plan)
814+
if (isSwitchableType(scrutinee.tpe)) recur(plan)
815+
else Nil
816816
}
817817

818818
/** Emit cases of a switch */

tests/pos/i3588.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

0 commit comments

Comments
 (0)