Skip to content

KaTypeRelationChecker

@SubclassOptInRequired(markerClass = [KaSessionComponentImplementationDetail::class])
interface KaTypeRelationChecker : KaSessionComponent

Inheritors

Properties

token

abstract val token: KaLifetimeToken

The KaLifetimeToken which determines the lifetime of the lifetime owner.

Functions

assertIsValidAndAccessible

isSubtypeOf

abstract fun KaType.isSubtypeOf(supertype: KaType, errorTypePolicy: KaSubtypingErrorTypePolicy = KaSubtypingErrorTypePolicy.STRICT): Boolean

Returns whether this KaType is a subtype of supertype. The relation is non-strict, i.e. any type t is a subtype of itself.

abstract fun KaType.isSubtypeOf(classId: ClassId, errorTypePolicy: KaSubtypingErrorTypePolicy = KaSubtypingErrorTypePolicy.STRICT): Boolean

Returns whether this KaType is a subtype of a class called classId.

This function provides a convenient way to check if a class extends a certain base class or interface while disregarding type arguments. For example, one may check if this KaType is a subtype of StandardClassIds.Iterable.

The errorTypePolicy is applied as such: If this KaType is an error type, the LENIENT policy leads to a trivially true result. Errors in type arguments are not considered, as the subclass check is concerned with the applied class type and not its type arguments.

This function for ClassIds is a convenient dual to other isSubtypeOf functions. As such, its result is the same as a call to isSubtypeOf with the following right-hand KaType: a.b.Class<*, *, ...>? given a class ID a.b.Class with all type arguments instantiated to a star projection.

This has the following interesting implications:

  • If the classId points to or actualizes to a type alias, subclassing is checked for the expanded type, as other isSubtypeOf implementations also take expansion into account. If the type alias doesn't expand to a KaClassType, isSubtypeOf is trivially false.

  • If the classId cannot be resolved, it effectively means that we would have an "unresolved symbol" error KaType on the right-hand side of isSubtypeOf. Hence, with a LENIENT error type policy, isSubtypeOf is true for all unresolved class IDs.

abstract fun KaType.isSubtypeOf(symbol: KaClassLikeSymbol, errorTypePolicy: KaSubtypingErrorTypePolicy = KaSubtypingErrorTypePolicy.STRICT): Boolean

Returns whether this KaType is a subtype of a class represented by symbol.

This function provides a convenient way to check if a class extends a certain base class or interface while disregarding type arguments.

The errorTypePolicy is applied as such: If this KaType is an error type, the LENIENT policy leads to a trivially true result. Errors in type arguments are not considered, as the subclass check is concerned with the applied class type and not its type arguments.

This function for KaClassLikeSymbols is a convenient dual to other isSubtypeOf functions. As such, its result is the same as a call to isSubtypeOf with the following right-hand KaType: a.b.Class<*, *, ...>? given a class called a.b.Class with all type arguments instantiated to a star projection.

This has the following interesting implication: If the symbol points to or actualizes to a type alias, subclassing is checked for the expanded type, as other isSubtypeOf implementations also take expansion into account. If the type alias doesn't expand to a KaClassType, isSubtypeOf is trivially false.

isValid

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

semanticallyEquals

abstract fun KaType.semanticallyEquals(other: KaType, errorTypePolicy: KaSubtypingErrorTypePolicy = KaSubtypingErrorTypePolicy.STRICT): Boolean

Returns whether this KaType is semantically equal to other.

Semantic equality stands in contrast to the structural equality implemented by KaType.equals. See KaType for a detailed discussion about structural vs. semantic type equality.

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.