diff --git a/backend/mirai-console/src/internal/util/CommonUtils.kt b/backend/mirai-console/src/internal/util/CommonUtils.kt index a28170631..d52b4a8b9 100644 --- a/backend/mirai-console/src/internal/util/CommonUtils.kt +++ b/backend/mirai-console/src/internal/util/CommonUtils.kt @@ -41,8 +41,27 @@ internal fun StackFrame.findLoader(): ClassLoader? { }.getOrNull() } +internal inline fun T?.ifNull(block: () -> T): T { + contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) } + return this ?: block() +} + @PublishedApi -internal inline fun assertionError(message: () -> String): Nothing { +internal inline fun assertionError(message: () -> String = { "Reached an unexpected branch." }): Nothing { contract { callsInPlace(message, InvocationKind.EXACTLY_ONCE) } throw AssertionError(message()) -} \ No newline at end of file +} + +@PublishedApi +internal inline fun assertUnreachable(message: () -> String = { "Reached an unexpected branch." }): Nothing { + contract { callsInPlace(message, InvocationKind.EXACTLY_ONCE) } + throw AssertionError(message()) +} + +@MarkerUnreachableClause +@PublishedApi +internal inline val UNREACHABLE_CLAUSE: Nothing + get() = assertUnreachable() + +@DslMarker +private annotation class MarkerUnreachableClause \ No newline at end of file