diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-05-22 17:34:06 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-05-25 13:40:35 +0200 |
commit | f4381866a8560ed65ce411c2f28ffd9b4df945e2 (patch) | |
tree | 7f9e3e882423296fcd7101211c256345fa0303d3 /test/junit | |
parent | 57be8a33ebbc8e7a7d64404fe5db74ef895c5891 (diff) | |
download | scala-f4381866a8560ed65ce411c2f28ffd9b4df945e2.tar.gz scala-f4381866a8560ed65ce411c2f28ffd9b4df945e2.tar.bz2 scala-f4381866a8560ed65ce411c2f28ffd9b4df945e2.zip |
Enable nullness analysis in the inliner
When inlining an instance call, the inliner has to ensure that a NPE
is still thrown if the receiver object is null. By using the nullness
analysis, we can avoid emitting this code in case the receiver object
is known to be not-null.
Diffstat (limited to 'test/junit')
-rw-r--r-- | test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala index 0fc3601603..b8c5f85c49 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala @@ -975,4 +975,20 @@ class InlinerTest extends ClearAfterClass { val List(c) = compile(code) assertInvoke(getSingleMethod(c, "t"), "java/lang/Error", "<init>") } + + @Test + def noRedunantNullChecks(): Unit = { + val code = + """class C { + | @inline final def f: String = "hai!" + | def t(c: C) = {c.f; c.f} // null check on the first, but not the second + |} + """.stripMargin + + val List(c) = compile(code) + val t = getSingleMethod(c, "t").instructions + assertNoInvoke(t) + assert(2 == t.collect({case Ldc(_, "hai!") => }).size) // twice the body of f + assert(1 == t.collect({case Jump(IFNONNULL, _) => }).size) // one single null check + } } |