Type inference in 1.4.30-M1 seems to have regresse...
# eap
z
Type inference in 1.4.30-M1 seems to have regressed significantly with generic bounds. Filed here https://youtrack.jetbrains.com/issue/KT-44045
d
cc @Victor Petukhov
v
Unfortunately, earlier it was a mistake to infer a type parameter to its upper bound without any other constraints (earlier the error didn’t appear by accident due to redundant incorporation of constraints). In inference, we don’t consider constraints to come from upper bounds as proper constraints in order to infer a type parameter only on their basis. You need to always have some other kind of explicit type source to infer a type parameter: value argument, explicit type argument, expected type, and so on.
Copy code
interface Foo

fun <T : Foo> foo(x: () -> T) {}
fun <T> materialize(): T = TODO()

fun <T : Foo> bar(): T {}

fun testing() {
    val x = foo(materialize()) // "Not enough information to infer parameter T" should be reported too
    val y = bar() // "Not enough information to infer parameter T" is already reported
}
Please use some explicit source of type to infer a type parameter. For materialization-like functions you can specify an expected type or type argument:
Copy code
fun testing() {
    val y: Foo = bar() // OK
    // or
    val z = bar<Foo>() // OK
}
z
I see, thanks for the detailed explanation 👍