From ff163edefd44d04352a09feab7845980fe171ef9 Mon Sep 17 00:00:00 2001 From: Water-OR Date: Thu, 24 Jul 2025 21:07:29 +0800 Subject: [PATCH] fix: contract of tryWithResources --- .../kotlin/net/llvg/utilities/scope/TryWithResources.kt | 6 ++++++ 1 file changed, 6 insertions(+) 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()