mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Add internal UNREACHABLE_CLAUSE, assertUnreachable, ifNull
This commit is contained in:
parent
fb82d8236d
commit
450e66ccfd
@ -41,8 +41,27 @@ internal fun StackFrame.findLoader(): ClassLoader? {
|
|||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal inline fun <T : Any> T?.ifNull(block: () -> T): T {
|
||||||
|
contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) }
|
||||||
|
return this ?: block()
|
||||||
|
}
|
||||||
|
|
||||||
@PublishedApi
|
@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) }
|
contract { callsInPlace(message, InvocationKind.EXACTLY_ONCE) }
|
||||||
throw AssertionError(message())
|
throw AssertionError(message())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
Loading…
Reference in New Issue
Block a user