Skip to content

KaScopeContext

A scope context includes all scopes that are relevant for a given KtElement position in a KtFile, together with all available implicit receivers.

See also

Properties

implicitReceivers

The implicit receivers available at the context position.

The list is sorted according to the order of scopes in the scope tower (from innermost to outermost).

It is possible to use this@ + KaImplicitReceiver.label to refer to the corresponding implicit receiver.

this (without any explicit label) can be used to explicitly refer to the (currently) implicit receiver with the lowest index in the scope tower (= innermost scope).

implicitValues

The implicit values available at the context position.

The list is sorted according to the order of scopes in the scope tower (from innermost to outermost).

See also

possibleSmartCasts

The list of smart casts available at the context position.

Note that an actual smart cast will only appear if the original expression type does not match the expected type. For actual smart cast application, check KaDataFlowProvider.smartCastInfo.

The list has an arbitrary (but stable) order.

scopes

abstract val scopes: List<KaScopeWithKind>

The KaScopes available at the context position. KaScopeWithKind additionally determines the kind of scope at the index in the scope tower.

The list is sorted according to the order of scopes in the scope tower (from innermost to outermost).

token

abstract val token: KaLifetimeToken

The KaLifetimeToken which determines the lifetime of the lifetime owner.

Functions

assertIsValidAndAccessible

compositeScope

context(session: KaSession)
fun KaScopeContext.compositeScope(filter: (KaScopeKind) -> Boolean = { true }): KaScope

Returns a single KaScope that contains declarations from all scopes that satisfy filter.

The order of declarations corresponds to the order of their containing scopes, which are sorted according to their indices in the scope tower.

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.