Skip to content

KaDiagnostic

A diagnostic message reported by the compiler checker.

Inheritors

Properties

defaultMessage

abstract val defaultMessage: String

The human-readable message rendered by the compiler to describe the error, warning, or info.

diagnosticClass

abstract val diagnosticClass: KClass<*>

factoryName

abstract val factoryName: String

A technical name identifying the diagnostic.

This is the same name as reported by the compiler when the -Xrender-internal-diagnostic-names compiler flag is enabled.

Example

fun test() {
    foo(1)
}

Because foo is not defined, the compiler reports an UNRESOLVED_REFERENCE error. This would also be the factoryName of the KaDiagnostic.

isSuppressed

abstract val isSuppressed: Boolean

Whether the diagnostic is suppressed at its use site, e.g., by a @Suppress annotation.

Suppressed diagnostics are not reported by the compiler, so they should not be presented to the user as is. By default, diagnostic collection filters them out; KaDiagnostics.ignoreSuppressed yields them as well.

The property is only meaningful for diagnostics obtained from diagnostic collection. For diagnostics obtained in another way, such as diagnostics of an unresolved call, the property is always false.

Example

@Suppress("UNUSED_VARIABLE")
fun foo() {
    val unused = 0
}

The UNUSED_VARIABLE diagnostic reported on unused is suppressed.

severity

abstract val severity: KaSeverity

The severity of the diagnostic (e.g. error or warning), which is determined from the compiler's classification of the diagnostic.

token

abstract val token: KaLifetimeToken

The KaLifetimeToken which determines the lifetime of the lifetime owner.

Functions

assertIsValidAndAccessible

getDefaultMessageWithFactoryName

Returns a formatted string of the diagnostic's factory name and default message.

isValid

Whether the lifetime owner is still valid, i.e. we are still in the scope of the lifetime owner's regular lifetime.

withValidityAssertion

inline fun <R> KaLifetimeOwner.withValidityAssertion(action: () -> R): R

Executes action only if the KaLifetimeOwner is still valid and accessible. Otherwise, throws a validity exception based on the concrete violation.