Hello, I’ve been struggling to understand why given the 2 snippets below, the first one compiles but the second one gives a type inference error.
First Snippet:
class A
class B
fun toB(a: A) = B()
fun List<A>.toB(): List<B> = this.map { toB(it) }
Second Snippet:
class A
class B
fun toB(a: A) = B()
fun List<A>.toB(): List<B> = this.map(::toB)
Thanks, filed an issue: https://youtrack.jetbrains.com/issue/KT-31630. The error is fixed in the experimental new inference algorithm, learn more on how to try it here: Kotlin 1.3.40 Early Access Preview
Thanks, look forward to it being fixed in stable!
I was under the impression that the compilation is still using the old type inference:
So changing to the 1.3.40 eap build wouldn’t actually help. You would still need to enable the new type inference for compilation.
That’s exactly right, thank you. To enable it on compilation you have to add a compiler argument -XXLanguage:+NewInference
.