https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
h

Hristijan

03/28/2024, 10:03 PM
Hey guys, is there any way to get contracts like callsInPlace working with
expect inline fun
? Or is there some known workaround at the moment without writing another function that's just a pass through?
a

Alexander Zhirkevich

04/02/2024, 1:52 PM
You can add body with contract for expect fun and suppress the error
Copy code
@OptIn(ExperimentalContracts::class)
@Suppress("EXPECTED_DECLARATION_WITH_BODY")
expect inline fun foo(block: () -> Unit) : Any {
    contract {
        callsInPlace(block, InvocationKind.EXACTLY_ONCE)
    }
    error("Unreachable")
}
thank you color 1
3 Views