From 453d072cc7e158fd1da18046c496768219e4ba78 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 17 Nov 2020 09:40:34 +0800 Subject: [PATCH] Add warning for ifNull on non-null value --- backend/mirai-console/src/internal/util/CommonUtils.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/mirai-console/src/internal/util/CommonUtils.kt b/backend/mirai-console/src/internal/util/CommonUtils.kt index d52b4a8b9..46411e7dd 100644 --- a/backend/mirai-console/src/internal/util/CommonUtils.kt +++ b/backend/mirai-console/src/internal/util/CommonUtils.kt @@ -41,11 +41,18 @@ internal fun StackFrame.findLoader(): ClassLoader? { }.getOrNull() } +@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") +@kotlin.internal.LowPriorityInOverloadResolution internal inline fun 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.ifNull(block: () -> T): T = this + @PublishedApi internal inline fun assertionError(message: () -> String = { "Reached an unexpected branch." }): Nothing { contract { callsInPlace(message, InvocationKind.EXACTLY_ONCE) }