Is this contract correct? ```public suspend inline...
# compiler
y
Is this contract correct?
Copy code
public suspend inline fun <A, B, C> parZip(
  crossinline fa: suspend () -> A,
  crossinline fb: suspend () -> B,
  crossinline f: suspend (A, B) -> C
): C {
  contract {
    callsInPlace(fa, InvocationKind.EXACTLY_ONCE)
    callsInPlace(fb, InvocationKind.EXACTLY_ONCE)
    callsInPlace(f, InvocationKind.EXACTLY_ONCE)
  }
  return coroutineScope {
    val faa = async { fa() }
    val fbb = async { fb() }
    val (a, b) = awaitAll(faa, fbb)
    f(a as A, b as B)
  }
}
Of course the compiler rejects them, that's not my question. Are the semantics of contracts valid for this case, so that I can just suppress the warnings, or is there a case where this contract can be violated by the behaviour of
parZip
? My thinking is that, because of the
awaitAll
and the
coroutineScope
, any effect that
fa
and
fb
have are guaranteed to be finished by the end of
parZip
, and hence that they are guaranteed to be invoked and finish invocation and throw all their exceptions and everything. Is my thinking correct? Could there be a strange cancellation scenario here that violates this contract?
e
the compiler rejects them
it does? compiles fine for me
y
As in it gives the warnings
LEAKED_IN_PLACE_LAMBDA
and
WRONG_INVOCATION_KIND
. This is K2 only I think. I should've clarified I meant that it emits warnings, and thus my question is should we suppress those warnings for this function, and in fact what is the most apt contract for this function?