Krzysztof
05/13/2020, 9:28 PMclass org.test.reactive.kitchen.SuspendedKitchen {
suspend fun getPotatoes(): Potatoes = ...
fun chop(potatoes: Potatoes): ChoppedPotatoes = ...
fun fry(fish: Fish): FriedFish = ...
suspend fun fry(choppedPotatoes: ChoppedPotatoes): Chips = ...
}
Now if I have code like that:
launch {
val kitchen = SuspendedKitchen()
val chips = kitchen.getPotatoes()
.let(kitchen::chop)
.let(kitchen::fry) // <-- does not work
}
The .let(kitchen:fry)
fails with:
Callable reference resolution ambiguity:
public final suspend fun fry(choppedPotatoes: ChoppedPotatoes): Chips defined in org.test.reactive.kitchen.SuspendedKitchen public final fun fry(fish: Fish): FriedFish defined in org.test.reactive.kitchen.SuspendedKitchen
It complains about totally different types so I don't know how is that ambiguous. Does suspend mess up type resolution?
But in such case why this one works fine:
launch {
val kitchen = SuspendedKitchen()
val chips = kitchen.getPotatoes()
.let(kitchen::chop)
.let { kitchen.fry(it) } // <-- works
}
Is that expected behavior? I don't see why they would behave differently?octylFractal
05/13/2020, 9:47 PMKrzysztof
05/13/2020, 9:48 PMoctylFractal
05/13/2020, 9:49 PMinline
methods like let
, but I presume that the issue is at least relatedinline
in a suspend
context always acts as if it it was declared suspend inline
, and the lambda was declared as a suspend
lambda as well. which would mean that when it tries to compile kitchen::fry
, it can either generate a normal lambda with the right parameters (but we need a suspend
lambda! so this doesn't work); or it can generate a suspend
lambda with the wrong parameters