diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-10-07 12:47:22 +0200 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-10-07 12:47:22 +0200 |
commit | d4601babe3b79e6cd354ed4e9fcd5feaaa47d2b0 (patch) | |
tree | 6f6a7f72f0ee5fea936bbc941874b8d37175a850 /test/junit | |
parent | d028d89ece11a886cce88e2c0e1d8443d6271e0c (diff) | |
parent | 0c25979244877b4431066700a6e945f145771c3c (diff) | |
download | scala-d4601babe3b79e6cd354ed4e9fcd5feaaa47d2b0.tar.gz scala-d4601babe3b79e6cd354ed4e9fcd5feaaa47d2b0.tar.bz2 scala-d4601babe3b79e6cd354ed4e9fcd5feaaa47d2b0.zip |
Merge pull request #4016 from lrytz/t8731
SI-8731 warning if @switch is ignored
Diffstat (limited to 'test/junit')
-rw-r--r-- | test/junit/scala/issues/BytecodeTests.scala | 39 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala | 3 |
2 files changed, 42 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) + } +} diff --git a/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala b/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala index 15bc1f427d..b892eb36cf 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala @@ -76,4 +76,7 @@ object CodeGenTools { def assertSameCode(actual: List[Instruction], expected: List[Instruction]): Unit = { assertTrue(s"\nExpected: $expected\nActual : $actual", actual === expected) } + + def getSingleMethod(classNode: ClassNode, name: String): Method = + convertMethod(classNode.methods.asScala.toList.find(_.name == name).get) } |