1594c1fc6b
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
30 lines
471 B
Kotlin
Vendored
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)
|
|
} |