Lambda parameter with default parameter in inline functions


My code looks simplified like this:

inline fun foo(x: Int, map: (Int) -> String = { "$it" }) = map(x)

Reports the error Construction is not yet supported in inline functions.

Is there a specific reason for this?

I don’t see the difficulty because calling foo(1) { "$it" } should be equivalent to foo(1). What am I missing? Or this is an oversight? Would it be hard to add?

Type inference in lambda default argument

It’s seems that default inline functions is a feature they wish to implement but is not yet supported.

inline fun foo(x: Int, noinline map: (Int) -> String = { "$it" }) = map(x)

This works, but defeats the purpose, since now the map lambda is never inlined.


Default values for functional parameters of inline functions will be supported in Kotlin 1.2, see KT-6884


Thanks! Looking forward to 1.2 then :slight_smile: