Refined redundant null check optimization

This commit is contained in:
Denis Zharkov
2014-12-31 16:19:21 +03:00
parent 5675d2b26b
commit 6f94ebb9d6
10 changed files with 139 additions and 5 deletions
@@ -0,0 +1,8 @@
fun box() {
val x = Array(1) { "" }
}
// 0 IFNULL
// 0 IFNONNULL
// 0 ATHROW
// 0 throwNpe
@@ -1,3 +1,5 @@
class A
fun foo(x: Any?) {}
fun box() {
@@ -8,6 +10,9 @@ fun box() {
z!!
foo(1 as java.lang.Integer)
val y: Any? = if (1 == 1) x else A()
y!!
}
// 0 IFNULL
@@ -0,0 +1,12 @@
fun box() {
val x: Any? = "abc"
val y: Any? = if (1 == 1) x else "cde"
x!!
y!!
}
// 0 IFNULL
// 0 IFNONNULL
// 0 throwNpe
// 0 ATHROW
@@ -0,0 +1,15 @@
class A
fun box() {
val x: A? = A()
val z: A? = A()
val z1: A? = if (1 == 1) z else x
x!!
z!!
z1!!
}
// 0 IFNULL
// 0 IFNONNULL
// 0 throwNpe
// 0 ATHROW
@@ -0,0 +1,18 @@
class A
fun box() {
val x: A? = A()
val y: A?
if (1 == 0) {
y = x
}
else {
y = null
}
y!!
}
// 0 IFNULL
// 1 IFNONNULL
// 1 throwNpe
// 0 ATHROW