Files
kotlin-fork/compiler/testData/codegen/box/inference/lastExpressionOfLambdaWithNothingConstraint.kt
T
Mikhail Zarechenskiy f702417655 [NI] Relax rules for call completion: require at least one constraint
It's enough to have at least one good constraint.

 Note that the whole algorithm can be a bit more general:
 we could check also Out<T>, In<T> and verify that T has good only
 lower constraint or upper constraint, but there are questions for
 types like Inv<Out<T>>, where T should have lower and upper constraints

 #KT-31514 Fixed
2019-05-29 02:14:00 +03:00

30 lines
479 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<String>()
} else {
null
}
}
}
fun box(): String {
return test(true)
}