If I have a function like: ```inline fun foo(block...
# getting-started
c
If I have a function like:
Copy code
inline fun foo(block: () -> String) {
    bar()

    block()
}
and
bar()
is documented that it should never throw in normal operations, am I allowed to declare
block
as
InvocationKind.EXACTLY_ONCE
? In the event that
bar()
throws an exception,
block()
will not be called, but then again the exception will bubble up breaking the caller too, so it shouldn't matter to them?
g
I think yes, you are allowed to add the contract. AFAIK,
EXACTLY_ONCE
is used only to understand local contracts (like "local variable is initialized"). But if the function throws, then the local scope will be destroyed (it will propagate the exception without continuing its execution), so the contracts do not matter anymore.
➕ 2
y
Indeed, this contract is valid no matter what. Calls in place is about normal return of this function. Exactly once means that if the function returns, the block has finished executing exactly once. This has further implications like if the block is known to throw, then this function must thus throw. Similarly with At least once, it guarantees that on normal return, the block got called to completion at least once. Where it gets "tricky" is with at most once. You might know that try-catch around a block doesn't count as exactly once. That's because, when the function returns normally, the block is thus not guaranteed to have executed fully. In other words, a block executing means that abnormal completion must result in the function's abnormal completion as well
c
Do you have a resource that lists all the InvocationKind and what each entails/what should be respected? The stdlib documentation doesn't say much.