Files
kotlin-fork/compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt
T
Mikhail Zarechenskiy 1594c1fc6b [NI] Don't consider Nothing-constraint as proper to complete call
Follow-up of 9b3e17f0. There we decided to complete call if a type
 variable from a return type has proper lower constraints, now we refine
 this rule wrt `Nothing`-like constraints to avoid inferring type variables
 to Nothing, which is quite useless

 #KT-30370 Fixed
2019-03-11 19:14:29 +03:00

30 lines
471 B
Kotlin
Vendored

// !LANGUAGE: +NewInference
// WITH_RUNTIME
inline fun <T> foo(f: () -> T): String {
return (f() as? Inv<T>)?.result() ?: "Bad"
}
class Inv<T> {
fun result(): String = "OK"
}
fun <K> create(): Inv<K> = Inv()
fun test(b: Boolean): String {
return foo {
if (!b) {
return@foo create<String>()
}
if (b) {
create()
} else {
null
}
}
}
fun box(): String {
return test(true)
}