summaryrefslogtreecommitdiff
path: root/test/files/run/t7852.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-09-18 17:13:35 +0200
committerJason Zaugg <jzaugg@gmail.com>2013-09-18 17:13:35 +0200
commit355eff4de30a2c32ea2041eb0bf306b22c0e0455 (patch)
tree38d63d31eb39f38034039299ffc830f5f4d7f2e3 /test/files/run/t7852.scala
parent354f4280f3bfbf033aa28100b4c74bc9b923dcbd (diff)
downloadscala-355eff4de30a2c32ea2041eb0bf306b22c0e0455.tar.gz
scala-355eff4de30a2c32ea2041eb0bf306b22c0e0455.tar.bz2
scala-355eff4de30a2c32ea2041eb0bf306b22c0e0455.zip
SI-7852 Refactor null-elision tests to be more focussed
- Directly count null checks, rather than diffing the textual bytecode of the entire method - Add a test to show that the LHS needs to be a direct module reference, not just a tree with a module type, to elide the null check.
Diffstat (limited to 'test/files/run/t7852.scala')
-rw-r--r--test/files/run/t7852.scala32
1 files changed, 21 insertions, 11 deletions
diff --git a/test/files/run/t7852.scala b/test/files/run/t7852.scala
index 3c930fbbc1..c93db718fd 100644
--- a/test/files/run/t7852.scala
+++ b/test/files/run/t7852.scala
@@ -1,21 +1,26 @@
import scala.tools.partest.BytecodeTest
+import scala.tools.asm
import scala.tools.asm.util._
import scala.tools.nsc.util.stringFromWriter
+import scala.collection.JavaConverters._
object Test extends BytecodeTest {
- def show {
- val classNode = loadClassNode("Lean")
- def showMethod(name: String) {
- val meth = getMethod(classNode, name)
- println(name)
- val textifier = new Textifier()
- meth.accept(new TraceMethodVisitor(textifier))
- println(stringFromWriter(w => textifier.print(w)))
- println()
+ val nullChecks = Set(asm.Opcodes.IFNONNULL, asm.Opcodes.IFNULL)
+
+ def show: Unit = {
+ def test(methodName: String, expected: Int) {
+ val classNode = loadClassNode("Lean")
+ val methodNode = getMethod(classNode, methodName)
+ val got = countNullChecks(methodNode.instructions)
+ assert(got == expected, s"expected $expected but got $got comparisons")
}
- showMethod("string")
- showMethod("module")
+ test("string", expected = 0)
+ test("module", expected = 0)
+ test("moduleIndirect", expected = 2)
}
+
+ def countNullChecks(insnList: asm.tree.InsnList): Int =
+ insnList.iterator.asScala.map(_.getOpcode).count(nullChecks)
}
class Lean {
@@ -26,4 +31,9 @@ class Lean {
def module {
Nil == (toString: Any)
}
+
+ def moduleIndirect {
+ val n: Nil.type = null
+ n == (toString: Any) // still need null checks here.
+ }
}