[FIR] Introduce UnsafeVariance attribute (see KT-41792)
This commit is contained in:
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.types
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
object CompilerConeAttributes {
|
||||
@@ -41,8 +40,19 @@ object CompilerConeAttributes {
|
||||
|
||||
override val key: KClass<out ExtensionFunctionType> = ExtensionFunctionType::class
|
||||
}
|
||||
|
||||
object UnsafeVariance : ConeAttribute<UnsafeVariance>() {
|
||||
val ANNOTATION_CLASS_ID = ClassId(FqName("kotlin"), Name.identifier("UnsafeVariance"))
|
||||
|
||||
override fun union(other: UnsafeVariance?): UnsafeVariance? = null
|
||||
override fun intersect(other: UnsafeVariance?): UnsafeVariance? = null
|
||||
override fun isSubtypeOf(other: UnsafeVariance?): Boolean = true
|
||||
|
||||
override val key: KClass<out UnsafeVariance> = UnsafeVariance::class
|
||||
}
|
||||
}
|
||||
|
||||
val ConeAttributes.exact: CompilerConeAttributes.Exact? by ConeAttributes.attributeAccessor<CompilerConeAttributes.Exact>()
|
||||
val ConeAttributes.noInfer: CompilerConeAttributes.NoInfer? by ConeAttributes.attributeAccessor<CompilerConeAttributes.NoInfer>()
|
||||
val ConeAttributes.extensionFunctionType: CompilerConeAttributes.ExtensionFunctionType? by ConeAttributes.attributeAccessor<CompilerConeAttributes.ExtensionFunctionType>()
|
||||
val ConeAttributes.unsafeVarianceType: CompilerConeAttributes.UnsafeVariance? by ConeAttributes.attributeAccessor<CompilerConeAttributes.UnsafeVariance>()
|
||||
|
||||
@@ -161,3 +161,13 @@ fun ConeKotlinType.isExtensionFunctionType(session: FirSession): Boolean {
|
||||
fun FirTypeRef.isExtensionFunctionType(session: FirSession): Boolean {
|
||||
return coneTypeSafe<ConeKotlinType>()?.isExtensionFunctionType(session) == true
|
||||
}
|
||||
|
||||
fun ConeKotlinType.isUnsafeVarianceType(session: FirSession): Boolean {
|
||||
val type = this.lowerBoundIfFlexible().fullyExpandedType(session)
|
||||
return type.attributes.unsafeVarianceType != null
|
||||
}
|
||||
|
||||
fun FirTypeRef.isUnsafeVarianceType(session: FirSession): Boolean {
|
||||
return coneTypeSafe<ConeKotlinType>()?.isUnsafeVarianceType(session) == true
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,7 @@ fun List<FirAnnotationCall>.computeTypeAttributes(): ConeAttributes {
|
||||
CompilerConeAttributes.Exact.ANNOTATION_CLASS_ID -> attributes += CompilerConeAttributes.Exact
|
||||
CompilerConeAttributes.NoInfer.ANNOTATION_CLASS_ID -> attributes += CompilerConeAttributes.NoInfer
|
||||
CompilerConeAttributes.ExtensionFunctionType.ANNOTATION_CLASS_ID -> attributes += CompilerConeAttributes.ExtensionFunctionType
|
||||
CompilerConeAttributes.UnsafeVariance.ANNOTATION_CLASS_ID -> attributes += CompilerConeAttributes.UnsafeVariance
|
||||
}
|
||||
}
|
||||
return ConeAttributes.create(attributes)
|
||||
|
||||
Reference in New Issue
Block a user