summaryrefslogtreecommitdiff
path: root/test/junit/scala/issues/BytecodeTests.scala
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2015-06-24 12:07:18 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2015-06-26 11:27:16 +0200
commitc8e7fdcfb20a2c9bf7345c998b2a2a4c174c4ebc (patch)
treee88dfa131bb7701786e788c259853d6207800595 /test/junit/scala/issues/BytecodeTests.scala
parentf50973159fb7a080d91f464a5fe0a1119ea330e6 (diff)
downloadscala-c8e7fdcfb20a2c9bf7345c998b2a2a4c174c4ebc.tar.gz
scala-c8e7fdcfb20a2c9bf7345c998b2a2a4c174c4ebc.tar.bz2
scala-c8e7fdcfb20a2c9bf7345c998b2a2a4c174c4ebc.zip
Default to delambdafy:method and backend:GenBCode
Switch the defaults of `-Ydelambdafy` and `-Ybackend`. Rewrite t6288b-jump-position test - no more icode Don't crash GenBCode beyond JVM code size limits A similar patch is in GenASM, see 3fa2c97 Fix check files for GenBCode / delambdafy:method defaults Force copy propagation test to ASM, see SI-9364 Force inline-ex-handlers test to GenASM, see SI-9364 Move t6613 test to pending - still broken in GenBCode Adding a `flags` file with `-Ybackend:GenASM` doesn't seem to have the desired effect. SI-6613 is re-opened. Force a few tests to GenASM, see SI-9364
Diffstat (limited to 'test/junit/scala/issues/BytecodeTests.scala')
-rw-r--r--test/junit/scala/issues/BytecodeTests.scala63
1 files changed, 60 insertions, 3 deletions
diff --git a/test/junit/scala/issues/BytecodeTests.scala b/test/junit/scala/issues/BytecodeTests.scala
index d4ed063a03..7c446894df 100644
--- a/test/junit/scala/issues/BytecodeTests.scala
+++ b/test/junit/scala/issues/BytecodeTests.scala
@@ -9,10 +9,17 @@ import scala.tools.nsc.backend.jvm.CodeGenTools._
import org.junit.Assert._
import scala.collection.JavaConverters._
import scala.tools.partest.ASMConverters._
+import scala.tools.testing.ClearAfterClass
+
+object BytecodeTests extends ClearAfterClass.Clearable {
+ var compiler = newCompiler()
+ def clear(): Unit = { compiler = null }
+}
@RunWith(classOf[JUnit4])
-class BytecodeTests {
- val compiler = newCompiler()
+class BytecodeTests extends ClearAfterClass {
+ ClearAfterClass.stateToClear = BytecodeTests
+ val compiler = BytecodeTests.compiler
@Test
def t8731(): Unit = {
@@ -59,7 +66,6 @@ class BytecodeTests {
|@AnnotB class B
""".stripMargin
- val compiler = newCompiler()
val run = new compiler.Run()
run.compileSources(List(new BatchSourceFile("AnnotA.java", annotA), new BatchSourceFile("AnnotB.java", annotB), new BatchSourceFile("Test.scala", scalaSrc)))
val outDir = compiler.settings.outputDirs.getSingleOutput.get
@@ -77,4 +83,55 @@ class BytecodeTests {
// a @Retention annotation are currently emitted as RUNTIME.
check("B.class", "AnnotB")
}
+
+ @Test
+ def t6288bJumpPosition(): Unit = {
+ val code =
+ """object Case3 { // 01
+ | def unapply(z: Any): Option[Int] = Some(-1) // 02
+ | def main(args: Array[String]) { // 03
+ | ("": Any) match { // 04
+ | case x : String => // 05
+ | println("case 0") // 06 println and jump at 6
+ | case _ => // 07
+ | println("default") // 08 println and jump at 8
+ | } // 09
+ | println("done") // 10
+ | }
+ |}
+ """.stripMargin
+ val List(mirror, module) = compileClasses(compiler)(code)
+
+ val unapplyLineNumbers = getSingleMethod(module, "unapply").instructions.filter(_.isInstanceOf[LineNumber])
+ assert(unapplyLineNumbers == List(LineNumber(2, Label(0))), unapplyLineNumbers)
+
+ import Opcodes._
+ val expected = List(
+ LineNumber(3, Label(0)),
+ LineNumber(4, Label(0)),
+ LineNumber(5, Label(5)),
+ Jump(IFNE, Label(11)),
+ Jump(GOTO, Label(20)),
+
+ LineNumber(6, Label(11)),
+ Invoke(INVOKEVIRTUAL, "scala/Predef$", "println", "(Ljava/lang/Object;)V", false),
+ Jump(GOTO, Label(33)),
+
+ LineNumber(5, Label(20)),
+ Jump(GOTO, Label(24)),
+
+ LineNumber(8, Label(24)),
+ Invoke(INVOKEVIRTUAL, "scala/Predef$", "println", "(Ljava/lang/Object;)V", false),
+ Jump(GOTO, Label(33)),
+
+ LineNumber(10, Label(33)),
+ Invoke(INVOKEVIRTUAL, "scala/Predef$", "println", "(Ljava/lang/Object;)V", false)
+ )
+
+ val mainIns = getSingleMethod(module, "main").instructions filter {
+ case _: LineNumber | _: Invoke | _: Jump => true
+ case _ => false
+ }
+ assertSameCode(mainIns, expected)
+ }
}