Extension Function isn't called


#1

I use Kotlin and React-Native on Android.

I made some extension function to be able to use react-native’s WritableMap more easily, like this:

fun WritableMap.put(name: String, b: Boolean) = this.putBoolean(name, b)
fun WritableMap.put(name: String, s: String) = this.putString(name, s)
fun WritableMap.put(name: String, i: Int) = this.putInt(name, i)
fun WritableMap.put(name: String, d: Double) = this.putDouble(name, d)
fun WritableMap.put(name: String, obj: Mappable) = this.putMap(name, obj.toMap())

interface Mappable {
    fun toMap(): WritableMap
}

fun WritableMap.put(name: String, list: List<Any>) = {
    throw IllegalArgumentException("I am never called!?")
    ....
}

Everything works except the last method for added a list, it’s just never called, even though it compiles fine and clicking on the invoking line in Android Studio jumps to it.


#2

This is why. You have a function that returns a lambda, which is never called.


#3

I just realised the same after one hour… :={


#4

KT-5068 might be your friend. Even though your case is excluded.