diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-09-18 17:13:35 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-09-18 17:13:35 +0200 |
commit | 355eff4de30a2c32ea2041eb0bf306b22c0e0455 (patch) | |
tree | 38d63d31eb39f38034039299ffc830f5f4d7f2e3 /test/files/run | |
parent | 354f4280f3bfbf033aa28100b4c74bc9b923dcbd (diff) | |
download | scala-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')
-rw-r--r-- | test/files/run/t7852.check | 38 | ||||
-rw-r--r-- | test/files/run/t7852.scala | 32 |
2 files changed, 21 insertions, 49 deletions
diff --git a/test/files/run/t7852.check b/test/files/run/t7852.check index ec63f5378c..e69de29bb2 100644 --- a/test/files/run/t7852.check +++ b/test/files/run/t7852.check @@ -1,38 +0,0 @@ -string - LDC "" - ALOAD 0 - INVOKEVIRTUAL java/lang/Object.toString ()Ljava/lang/String; - INVOKEVIRTUAL java/lang/Object.equals (Ljava/lang/Object;)Z - IFEQ L0 - ICONST_1 - GOTO L1 - L0 - FRAME SAME - ICONST_0 - L1 - FRAME SAME1 I - POP - RETURN - MAXSTACK = 2 - MAXLOCALS = 1 - - -module - GETSTATIC scala/collection/immutable/Nil$.MODULE$ : Lscala/collection/immutable/Nil$; - ALOAD 0 - INVOKEVIRTUAL java/lang/Object.toString ()Ljava/lang/String; - INVOKEVIRTUAL java/lang/Object.equals (Ljava/lang/Object;)Z - IFEQ L0 - ICONST_1 - GOTO L1 - L0 - FRAME SAME - ICONST_0 - L1 - FRAME SAME1 I - POP - RETURN - MAXSTACK = 2 - MAXLOCALS = 1 - - 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. + } } |