Oliver.O
11/12/2023, 6:13 PMLeaked in-place lambda: block: suspend (T) -> RWhat is the compiler trying to tell me? (Code in 🧵)
suspend fun <T : ExecutorCoroutineDispatcher, R> T.useWithBlockHound(block: suspend (T) -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
var exception: Throwable? = null
try {
return block(this)
} catch (e: Throwable) {
exception = e
throw e
} finally {
withContext(NonCancellable) {
withBlockHoundMode(BlockHoundMode.DISABLED) {
closeFinally(exception)
}
}
}
}
One warning message is referring to the line contract {
.
A second one refers to return block(this)
.block: suspend (T) -> R has wrong invocation kind: given EXACTLY_ONCE case, but ZERO case is possiblewarning at line
contract {
, but for that I've already filed KT-63414.dmitriy.novozhilov
11/12/2023, 7:06 PMOliver.O
11/12/2023, 8:13 PMcallsInPlace
must be inline
. If I change the above accordingly, the "leaked in-place lambda" warnings disappear. Created KT-63416.