diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinExceptionWithAttachments.kt b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinExceptionWithAttachments.kt index 8abbcc9a365..0ad3b36d97f 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinExceptionWithAttachments.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinExceptionWithAttachments.kt @@ -7,6 +7,8 @@ package org.jetbrains.kotlin.utils import com.intellij.openapi.diagnostic.Attachment import com.intellij.openapi.diagnostic.ExceptionWithAttachments +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract open class KotlinExceptionWithAttachments : RuntimeException, ExceptionWithAttachments { private val attachments = mutableListOf() @@ -27,7 +29,10 @@ open class KotlinExceptionWithAttachments : RuntimeException, ExceptionWithAttac } } +@OptIn(ExperimentalContracts::class) inline fun checkWithAttachment(value: Boolean, lazyMessage: () -> String, attachments: (KotlinExceptionWithAttachments) -> Unit = {}) { + contract { returns() implies(value) } + if (!value) { val e = KotlinExceptionWithAttachments(lazyMessage()) attachments(e)