diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-09-23 01:44:55 -0700 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-09-23 01:44:55 -0700 |
commit | 469d303d7b0b052880f0365f304ca7df09148ec4 (patch) | |
tree | 4fd1e5297a22b5a36db512319893f8112c1219d4 /test | |
parent | 65817bd2b71f5ea0e39af1b1c2b085562cd8e925 (diff) | |
parent | 355eff4de30a2c32ea2041eb0bf306b22c0e0455 (diff) | |
download | scala-469d303d7b0b052880f0365f304ca7df09148ec4.tar.gz scala-469d303d7b0b052880f0365f304ca7df09148ec4.tar.bz2 scala-469d303d7b0b052880f0365f304ca7df09148ec4.zip |
Merge pull request #2954 from retronym/ticket/7852
Avoid null checks when emitting "".== and SomeModule.==
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/t7852.check | 0 | ||||
-rw-r--r-- | test/files/run/t7852.flags | 1 | ||||
-rw-r--r-- | test/files/run/t7852.scala | 39 |
3 files changed, 40 insertions, 0 deletions
diff --git a/test/files/run/t7852.check b/test/files/run/t7852.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/run/t7852.check diff --git a/test/files/run/t7852.flags b/test/files/run/t7852.flags new file mode 100644 index 0000000000..f6262fd3e0 --- /dev/null +++ b/test/files/run/t7852.flags @@ -0,0 +1 @@ +-Ynooptimise diff --git a/test/files/run/t7852.scala b/test/files/run/t7852.scala new file mode 100644 index 0000000000..c93db718fd --- /dev/null +++ b/test/files/run/t7852.scala @@ -0,0 +1,39 @@ +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 { + 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") + } + 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 { + def string { + "" == toString + } + + def module { + Nil == (toString: Any) + } + + def moduleIndirect { + val n: Nil.type = null + n == (toString: Any) // still need null checks here. + } +} |