diff options
author | Linnea Gräf <nea@nea.moe> | 2024-10-16 19:24:24 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-10-16 19:24:24 +0200 |
commit | 7de0e8e7e09e3428c17ca9717c21c02469c31b76 (patch) | |
tree | f8c3d32a286521967a27877231c1ee74fa8c87ab /src/main/kotlin/util/assertions.kt | |
parent | 854ec336cc6a0a3bb60f33acfac28ed45b491a15 (diff) | |
download | firmament-7de0e8e7e09e3428c17ca9717c21c02469c31b76.tar.gz firmament-7de0e8e7e09e3428c17ca9717c21c02469c31b76.tar.bz2 firmament-7de0e8e7e09e3428c17ca9717c21c02469c31b76.zip |
Add edit backpacks button to /firm storage
Diffstat (limited to 'src/main/kotlin/util/assertions.kt')
-rw-r--r-- | src/main/kotlin/util/assertions.kt | 12 |
1 files changed, 11 insertions, 1 deletions
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 <T : Any> 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 <T : Any> 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() } |