diff --git a/lib/src/main/kotlin/net/llvg/utilities/scope/TryWithResources.kt b/lib/src/main/kotlin/net/llvg/utilities/scope/TryWithResources.kt index bfe0e4d..5fb051b 100644 --- a/lib/src/main/kotlin/net/llvg/utilities/scope/TryWithResources.kt +++ b/lib/src/main/kotlin/net/llvg/utilities/scope/TryWithResources.kt @@ -2,6 +2,8 @@ package net.llvg.utilities.scope +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract import kotlin.internal.InlineOnly import net.llvg.utilities.noExcept @@ -27,6 +29,10 @@ internal data class TryWithResourcesScopeImpl( @InlineOnly public inline fun tryWithResources(action: TryWithResourcesScope.() -> R): R { + contract { + callsInPlace(action, InvocationKind.EXACTLY_ONCE) + } + val resources: MutableList = ArrayList() return try { TryWithResourcesScopeImpl(resources).action()