Files
kotlin/compiler/testData/codegen/box/funInterface/nullableSam.kt
2020-02-04 16:14:29 +03:00

26 lines
645 B
Kotlin
Vendored

// !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS, JS_IR
// WITH_RUNTIME
fun interface KRunnable {
fun invoke()
}
fun isNull(r: KRunnable?): Boolean {
if (r == null) return true
r.invoke()
return false
}
fun nullableFun(fromNull: Boolean): (() -> Unit)? =
if (fromNull) null else {{}}
fun box(): String {
if (!isNull(nullableFun(true))) return "Fail 1"
if (isNull(nullableFun(false))) return "Fail 2"
if (!isNull(null)) return "Fail 3"
if (isNull {}) return "Fail 4"
return "OK"
}