@Jire Unfortunately this does not work. But I understand this is a tradeoff between clarity and convenience. I’m sure Kotlin chose clarity here by allowing only one receiver in a ‘with’ function. I must agree with Ilya that having multiple receivers will make it unclear with prop/func refers to with receiver.
@Suppress("SUBTYPING_BETWEEN_CONTEXT_RECEIVERS") // Hopefully this error gets fixed soon, but basically it happens when you have generic receivers that "might", but don't necessarily, have a subtyping relation
inline fun <A, B, R> with(a: A, b: B, block: context(A, B) () -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return block(a, b)
}
// repeat the above declaration for however many times you want.