diff --git a/core/src/commonMain/kotlin/Util.kt b/core/src/commonMain/kotlin/Util.kt index 7daf72aa5da1..4f54cb3ae109 100644 --- a/core/src/commonMain/kotlin/Util.kt +++ b/core/src/commonMain/kotlin/Util.kt @@ -29,8 +29,10 @@ import kotlin.contracts.contract import kotlin.reflect.KClass internal inline fun catchNotFound(block: () -> T): T? { + // block is called exactly once, but might not be executed fully, even if catchNotFound returns normally + // -> AT_MOST_ONCE, see https://youtrack.jetbrains.com/issue/KT-63414 contract { - callsInPlace(block, InvocationKind.EXACTLY_ONCE) + callsInPlace(block, InvocationKind.AT_MOST_ONCE) } return try { block() @@ -41,8 +43,10 @@ internal inline fun catchNotFound(block: () -> T): T? { } internal inline fun catchDiscordError(vararg codes: JsonErrorCode, block: () -> T): T? { + // block is called exactly once, but might not be executed fully, even if catchDiscordError returns normally + // -> AT_MOST_ONCE, see https://youtrack.jetbrains.com/issue/KT-63414 contract { - callsInPlace(block, InvocationKind.EXACTLY_ONCE) + callsInPlace(block, InvocationKind.AT_MOST_ONCE) } return try { block() diff --git a/core/src/commonMain/kotlin/builder/kord/KordBuilder.kt b/core/src/commonMain/kotlin/builder/kord/KordBuilder.kt index c9c1cafc5364..04272a756334 100644 --- a/core/src/commonMain/kotlin/builder/kord/KordBuilder.kt +++ b/core/src/commonMain/kotlin/builder/kord/KordBuilder.kt @@ -34,8 +34,6 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.serialization.json.Json -import kotlin.contracts.InvocationKind -import kotlin.contracts.contract private val gatewayInfoJson = Json { ignoreUnknownKeys = true } @@ -169,7 +167,6 @@ public abstract class BaseKordBuilder internal constructor(public val token: Str * ``` */ public fun cache(builder: KordCacheBuilder.(resources: ClientResources) -> Unit) { - contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } val old = cacheBuilder cacheBuilder = { resources: ClientResources -> old(resources) diff --git a/rest/src/commonMain/kotlin/builder/channel/EditGuildChannelBuilder.kt b/rest/src/commonMain/kotlin/builder/channel/EditGuildChannelBuilder.kt index 6797454ee60b..35f79a06bd32 100644 --- a/rest/src/commonMain/kotlin/builder/channel/EditGuildChannelBuilder.kt +++ b/rest/src/commonMain/kotlin/builder/channel/EditGuildChannelBuilder.kt @@ -195,7 +195,7 @@ public class MediaChannelModifyBuilder : PermissionOverwritesModifyBuilder, private var _availableTags: Optional> = Optional.Missing() public var availableTags: MutableList? by ::_availableTags.delegate() - public fun tag(name: String, builder: ForumTagBuilder.() -> Unit = {}) { + public inline fun tag(name: String, builder: ForumTagBuilder.() -> Unit = {}) { contract { callsInPlace(builder, InvocationKind.EXACTLY_ONCE) } val tag = ForumTagBuilder(name).apply(builder).toRequest() availableTags?.add(tag) ?: run { availableTags = mutableListOf(tag) }