Add warning for ifNull on non-null value

This commit is contained in:
Him188 2020-11-17 09:40:34 +08:00
parent 136b0c11d8
commit 453d072cc7

View File

@ -41,11 +41,18 @@ internal fun StackFrame.findLoader(): ClassLoader? {
}.getOrNull()
}
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@kotlin.internal.LowPriorityInOverloadResolution
internal inline fun <T : Any> T?.ifNull(block: () -> T): T {
contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) }
return this ?: block()
}
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Useless ifNull on not null value.")
@JvmName("ifNull1")
internal inline fun <T : Any> T.ifNull(block: () -> T): T = this
@PublishedApi
internal inline fun assertionError(message: () -> String = { "Reached an unexpected branch." }): Nothing {
contract { callsInPlace(message, InvocationKind.EXACTLY_ONCE) }