# Type Inference on Function Reference?

**URL:** <https://discuss.kotlinlang.org/t/type-inference-on-function-reference/12820>\
**Category:** Support\
**Created:** [May 24, 2019, 7:28am UTC](https://discuss.kotlinlang.org/t/type-inference-on-function-reference/12820 "2019-05-24T07:28:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickaleks](https://avatars.discourse-cdn.com/v4/letter/n/4af34b/32.png) [@nickaleks](https://discuss.kotlinlang.org/u/nickaleks)\
**Post date:** [May 24, 2019, 7:28am UTC](https://discuss.kotlinlang.org/t/type-inference-on-function-reference/12820/1 "2019-05-24T07:28:23Z")

</div>

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)

```

---

<div class="post-metadata">

**Author:** ![Alexey.Belkov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/alexey.belkov/32/5215_2.png) [@Alexey.Belkov](https://discuss.kotlinlang.org/u/Alexey.Belkov)\
**Post date:** [May 27, 2019, 12:08pm UTC](https://discuss.kotlinlang.org/t/type-inference-on-function-reference/12820/2 "2019-05-27T12:08:16Z")

</div>

Thanks, filed an issue: [https://youtrack.jetbrains.com/issue/KT-31630](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](https://discuss.kotlinlang.org/t/kotlin-1-3-40-early-access-preview/12775)

---

<div class="post-metadata">

**Author:** ![nickaleks](https://avatars.discourse-cdn.com/v4/letter/n/4af34b/32.png) [@nickaleks](https://discuss.kotlinlang.org/u/nickaleks)\
**Post date:** [May 28, 2019, 1:20pm UTC](https://discuss.kotlinlang.org/t/type-inference-on-function-reference/12820/3 "2019-05-28T13:20:14Z")

</div>

Thanks, look forward to it being fixed in stable!

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [May 28, 2019, 4:55pm UTC](https://discuss.kotlinlang.org/t/type-inference-on-function-reference/12820/4 "2019-05-28T16:55:35Z")

</div>

> [@Alexey.Belkov](#):
>
> learn more on how to try it here: [Kotlin 1.3.40 Early Access Preview](https://discuss.kotlinlang.org/t/kotlin-1-3-40-early-access-preview/12775)

I was under the impression that the compilation is still using the old type inference:

> [@Kotlin 1.3.40 Early Access Preview](https://discuss.kotlinlang.org/t/kotlin-1-3-40-early-access-preview/12775/1):
>
> Now _new type inference_ , which has been experimental since 1.3.0, is [enabled by default](https://youtrack.jetbrains.com/issue/KT-30453) in the plugin, but not for compilation.

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.

---

<div class="post-metadata">

**Author:** ![Alexey.Belkov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/alexey.belkov/32/5215_2.png) [@Alexey.Belkov](https://discuss.kotlinlang.org/u/Alexey.Belkov)\
**Post date:** [May 28, 2019, 5:33pm UTC](https://discuss.kotlinlang.org/t/type-inference-on-function-reference/12820/5 "2019-05-28T17:33:31Z")

</div>

That’s exactly right, thank you. To enable it on compilation you have to add a compiler argument `-XXLanguage:+NewInference`.
