https://kotlinlang.org logo
Title
k

Krzysztof

05/13/2020, 9:28 PM
Hi, I am new to Kolin (my second day using it) and trying to understand compilation error I have with coroutines. I have a class that looks more or less like that:
class 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?
k

Krzysztof

05/13/2020, 9:48 PM
Ah, ok thanks
o

octylFractal

05/13/2020, 9:49 PM
I know that those don't directly deal with
inline
methods like
let
, but I presume that the issue is at least related
like, perhaps an
inline
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
not 100% sure that's what the compiler does though