From f4a74f7eefb0521c0531f930ac8fd505953e0f50 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Mon, 9 Nov 2015 12:44:07 +0100 Subject: Rewrite test: no null in patmat --- .../nsc/transform/patmat/PatmatBytecodeTest.scala | 13 ++++++++++++ test/pending/jvm/patmat_opt_no_nullcheck.check | 1 - test/pending/jvm/patmat_opt_no_nullcheck.flags | 1 - .../jvm/patmat_opt_no_nullcheck/Analyzed_1.scala | 24 ---------------------- .../pending/jvm/patmat_opt_no_nullcheck/test.scala | 14 ------------- 5 files changed, 13 insertions(+), 40 deletions(-) delete mode 100644 test/pending/jvm/patmat_opt_no_nullcheck.check delete mode 100644 test/pending/jvm/patmat_opt_no_nullcheck.flags delete mode 100644 test/pending/jvm/patmat_opt_no_nullcheck/Analyzed_1.scala delete mode 100644 test/pending/jvm/patmat_opt_no_nullcheck/test.scala diff --git a/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala b/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala index b53f7693dc..5aac1f4656 100644 --- a/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala +++ b/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala @@ -102,4 +102,17 @@ class PatmatBytecodeTest extends ClearAfterClass { "y", ARETURN)) } + @Test + def optNoNullCheck(): Unit = { + val code = + """case class Foo(x: Any) + |class C { + | def a = (Foo(1): Any) match { + | case Foo(_: String) => + | } + |} + """.stripMargin + val c = compileClasses(optCompiler)(code).head + assert(!getSingleMethod(c, "a").instructions.exists(i => i.opcode == IFNULL || i.opcode == IFNONNULL), textify(findAsmMethod(c, "a"))) + } } diff --git a/test/pending/jvm/patmat_opt_no_nullcheck.check b/test/pending/jvm/patmat_opt_no_nullcheck.check deleted file mode 100644 index 43f53aba12..0000000000 --- a/test/pending/jvm/patmat_opt_no_nullcheck.check +++ /dev/null @@ -1 +0,0 @@ -bytecode identical diff --git a/test/pending/jvm/patmat_opt_no_nullcheck.flags b/test/pending/jvm/patmat_opt_no_nullcheck.flags deleted file mode 100644 index 453b6b7895..0000000000 --- a/test/pending/jvm/patmat_opt_no_nullcheck.flags +++ /dev/null @@ -1 +0,0 @@ --Yopt:l:project \ No newline at end of file diff --git a/test/pending/jvm/patmat_opt_no_nullcheck/Analyzed_1.scala b/test/pending/jvm/patmat_opt_no_nullcheck/Analyzed_1.scala deleted file mode 100644 index 1e4d564cdf..0000000000 --- a/test/pending/jvm/patmat_opt_no_nullcheck/Analyzed_1.scala +++ /dev/null @@ -1,24 +0,0 @@ -// this class's bytecode, compiled under -optimize is analyzed by the test -// method a's bytecode should be identical to method b's bytecode -case class Foo(x: Any) - -class SameBytecode { - def a = - (Foo(1): Any) match { - case Foo(_: String) => - } - - // there's no null check - def b: Unit = { - val x1: Any = Foo(1) - if (x1.isInstanceOf[Foo]) { - val x3 = x1.asInstanceOf[Foo] - if (x3.x.isInstanceOf[String]) { - val x = () - return - } - } - - throw new MatchError(x1) - } -} \ No newline at end of file diff --git a/test/pending/jvm/patmat_opt_no_nullcheck/test.scala b/test/pending/jvm/patmat_opt_no_nullcheck/test.scala deleted file mode 100644 index 5a4a398b67..0000000000 --- a/test/pending/jvm/patmat_opt_no_nullcheck/test.scala +++ /dev/null @@ -1,14 +0,0 @@ -/* - * filter: inliner warning; re-run with - */ -import scala.tools.partest.{ BytecodeTest, ASMConverters } - -object Test extends BytecodeTest { - def show: Unit = { - val classNode = loadClassNode("SameBytecode") - // ASM and GenBCode assign variable slots slightly differently - val instrsA = ASMConverters.instructionsFromMethod(getMethod(classNode, "a")) - val instrsB = ASMConverters.instructionsFromMethod(getMethod(classNode, "b")) - assert(ASMConverters.equivalentBytecode(instrsA, instrsB), diffInstructions(instrsA, instrsB)) // doesn't work - } -} -- cgit v1.2.3