Properly check expression nullability on attempt to apply == optimizations

#Fix KT-19767
This commit is contained in:
Mikhael Bogdanov
2017-08-22 12:20:33 +02:00
parent f0035a7be0
commit 1a05df204e
9 changed files with 193 additions and 2 deletions
@@ -0,0 +1,34 @@
// IGNORE_BACKEND: JS, NATIVE
// FILE: M.java
public class M {
private final Integer value;
public M(Integer value) {
this.value = value;
}
public Integer nulled() {
return value;
}
}
// FILE: Kotlin.kt
fun foo(p: Int?): Boolean {
return M(p)?.nulled() == 1
}
fun foo2(p: Int?): Boolean {
return 1 == M(p)?.nulled()
}
fun box(): String {
if (foo(null)) return "fail 1"
if (!foo(1)) return "fail 2"
if (foo2(null)) return "fail 1"
if (!foo2(1)) return "fail 2"
return "OK"
}