summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala4
-rw-r--r--test/files/pos/switch-small.scala8
2 files changed, 11 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index 809dbe7695..c25f33393a 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -407,7 +407,9 @@ abstract class ExplicitOuter extends InfoTransform
if (unchecked)
nselector = nselector1
- (!unchecked, isSwitchAnnotation(tpt.tpe))
+ // Don't require a tableswitch if there are 1-2 casedefs
+ // since the matcher intentionally emits an if-then-else.
+ (!unchecked, isSwitchAnnotation(tpt.tpe) && ncases.size > 2)
case _ =>
(true, false)
}
diff --git a/test/files/pos/switch-small.scala b/test/files/pos/switch-small.scala
new file mode 100644
index 0000000000..9de9ca028e
--- /dev/null
+++ b/test/files/pos/switch-small.scala
@@ -0,0 +1,8 @@
+import annotation._
+
+object Test {
+ def f(x: Int) = (x: @switch) match {
+ case 1 => 1
+ case _ => 2
+ }
+}