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,21 @@
fun foo(p: Int?): Boolean {
return M<Int>(p)?.nulled() == 1
}
fun foo2(p: Int?): Boolean {
return 1 == M<Int>(p)?.nulled()
}
class M<T: Any>(val z: T?) {
fun nulled(): T? = z
}
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"
}