Avoid object's interpretation with nullable type

#KT-56215 Fixed
This commit is contained in:
Ivan Kylchik
2023-02-12 17:30:21 +01:00
committed by Space Team
parent 99448b77f3
commit 477d092bb8
15 changed files with 92 additions and 6 deletions
@@ -0,0 +1,22 @@
object ObjectWithExtension
fun ObjectWithExtension?.nullableExtensionFun(): String =
if(this == null)
"Null"
else
"Not null"
fun ObjectWithExtension.extensionFun(): String =
if(this == null)
"Null" // unreachable branch, will be optimized by interpreter
else
"Not null"
fun box(): String {
val nullObjectWithExtension: ObjectWithExtension? = null
if ("${nullObjectWithExtension.nullableExtensionFun()}" != "Null") return "Fail 1"
if ("${ObjectWithExtension.nullableExtensionFun()}" != "Not null") return "Fail 2"
if ("${ObjectWithExtension.extensionFun()}" != "Not null") return "Fail 3"
return "OK"
}