diff options
Diffstat (limited to 'test/files')
-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. + } } |