summaryrefslogtreecommitdiff
path: root/test/junit/scala/issues/BytecodeTests.scala
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2014-09-29 17:52:40 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2014-10-06 20:56:32 +0200
commit0c25979244877b4431066700a6e945f145771c3c (patch)
tree92d631fc91e90c55508eda2b4aa460c2ba29658c /test/junit/scala/issues/BytecodeTests.scala
parenta52db7f1639c6d48eaa64ae609385a60467fd566 (diff)
downloadscala-0c25979244877b4431066700a6e945f145771c3c.tar.gz
scala-0c25979244877b4431066700a6e945f145771c3c.tar.bz2
scala-0c25979244877b4431066700a6e945f145771c3c.zip
SI-8731 warning if @switch is ignored
For matches with two or fewer cases, @switch is ignored. This should not happen silently.
Diffstat (limited to 'test/junit/scala/issues/BytecodeTests.scala')
-rw-r--r--test/junit/scala/issues/BytecodeTests.scala39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/junit/scala/issues/BytecodeTests.scala b/test/junit/scala/issues/BytecodeTests.scala
new file mode 100644
index 0000000000..7a05472277
--- /dev/null
+++ b/test/junit/scala/issues/BytecodeTests.scala
@@ -0,0 +1,39 @@
+package scala.issues
+
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.junit.Test
+import scala.tools.asm.Opcodes
+import scala.tools.nsc.backend.jvm.CodeGenTools._
+import org.junit.Assert._
+import scala.collection.JavaConverters._
+import scala.tools.partest.ASMConverters._
+
+@RunWith(classOf[JUnit4])
+class BytecodeTests {
+ val compiler = newCompiler()
+
+ @Test
+ def t8731(): Unit = {
+ val code =
+ """class C {
+ | def f(x: Int) = (x: @annotation.switch) match {
+ | case 1 => 0
+ | case 2 => 1
+ | case 3 => 2
+ | }
+ | final val K = 10
+ | def g(x: Int) = (x: @annotation.switch) match {
+ | case K => 0
+ | case 1 => 10
+ | case 2 => 20
+ | }
+ |}
+ """.stripMargin
+
+ val List(c) = compileClasses(compiler)(code)
+
+ assertTrue(getSingleMethod(c, "f").instructions.count(_.isInstanceOf[TableSwitch]) == 1)
+ assertTrue(getSingleMethod(c, "g").instructions.count(_.isInstanceOf[LookupSwitch]) == 1)
+ }
+}