From 7de0e8e7e09e3428c17ca9717c21c02469c31b76 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Wed, 16 Oct 2024 19:24:24 +0200 Subject: Add edit backpacks button to /firm storage --- src/main/kotlin/util/assertions.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/main/kotlin/util/assertions.kt') diff --git a/src/main/kotlin/util/assertions.kt b/src/main/kotlin/util/assertions.kt index 6f2ed19..86982be 100644 --- a/src/main/kotlin/util/assertions.kt +++ b/src/main/kotlin/util/assertions.kt @@ -1,11 +1,18 @@ - +@file:OptIn(ExperimentalContracts::class) package moe.nea.firmament.util +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract + /** * Less aggressive version of `require(obj != null)`, which fails in devenv but continues at runtime. */ inline fun assertNotNullOr(obj: T?, message: String? = null, block: () -> T): T { + contract { + callsInPlace(block, InvocationKind.AT_MOST_ONCE) + } if (message == null) assert(obj != null) else @@ -18,6 +25,9 @@ inline fun assertNotNullOr(obj: T?, message: String? = null, block: () * Less aggressive version of `require(condition)`, which fails in devenv but continues at runtime. */ inline fun assertTrueOr(condition: Boolean, block: () -> Unit) { + contract { + callsInPlace(block, InvocationKind.AT_MOST_ONCE) + } assert(condition) if (!condition) block() } -- cgit