FIR2IR: support RawType internal annotation
This commit is contained in:
committed by
TeamCityServer
parent
f8a6ab9536
commit
5b058cfcdc
+3
@@ -40,6 +40,7 @@ class Fir2IrJvmSpecialAnnotationSymbolProvider : Fir2IrSpecialSymbolProvider() {
|
||||
when (id) {
|
||||
ENHANCED_NULLABILITY_ID -> id.toIrClass(kotlinJvmInternalPackage).symbol
|
||||
FLEXIBLE_NULLABILITY_ID -> id.toIrClass(kotlinInternalIrPackage).symbol
|
||||
RAW_TYPE_ANNOTATION_ID -> id.toIrClass(kotlinInternalIrPackage).symbol
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -59,5 +60,7 @@ class Fir2IrJvmSpecialAnnotationSymbolProvider : Fir2IrSpecialSymbolProvider() {
|
||||
private val ENHANCED_NULLABILITY_ID = ClassId.topLevel(JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION)
|
||||
private val FLEXIBLE_NULLABILITY_ID =
|
||||
ClassId.topLevel(IrBuiltIns.KOTLIN_INTERNAL_IR_FQN.child(Name.identifier("FlexibleNullability")))
|
||||
private val RAW_TYPE_ANNOTATION_ID =
|
||||
ClassId.topLevel(IrBuiltIns.KOTLIN_INTERNAL_IR_FQN.child(Name.identifier("RawType")))
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,13 @@ class Fir2IrBuiltIns(
|
||||
internal fun extensionFunctionTypeAnnotationConstructorCall(): IrConstructorCall? =
|
||||
extensionFunctionTypeAnnotationSymbol?.toConstructorCall()
|
||||
|
||||
private val rawTypeAnnotationSymbol by lazy {
|
||||
annotationSymbolById(StandardClassIds.Annotations.RawTypeAnnotation)
|
||||
}
|
||||
|
||||
internal fun rawTypeAnnotationConstructorCall(): IrConstructorCall? =
|
||||
rawTypeAnnotationSymbol?.toConstructorCall()
|
||||
|
||||
private fun annotationSymbolById(id: ClassId): IrClassSymbol? =
|
||||
provider?.getClassSymbolById(id) ?: session.symbolProvider.getClassLikeSymbolByClassId(id)?.toSymbol(
|
||||
session, classifierStorage, ConversionTypeContext.DEFAULT
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.name.StandardClassIds.Annotations.ExtensionFunctionType
|
||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
@@ -100,7 +101,8 @@ class Fir2IrTypeConverter(
|
||||
fun ConeKotlinType.toIrType(
|
||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT,
|
||||
annotations: List<FirAnnotation> = emptyList(),
|
||||
hasFlexibleNullability: Boolean = false
|
||||
hasFlexibleNullability: Boolean = false,
|
||||
addRawTypeAnnotation: Boolean = false
|
||||
): IrType {
|
||||
return when (this) {
|
||||
is ConeKotlinErrorType -> createErrorType()
|
||||
@@ -122,13 +124,6 @@ class Fir2IrTypeConverter(
|
||||
typeAnnotations += it
|
||||
}
|
||||
}
|
||||
isExtensionFunctionType -> {
|
||||
if (annotations.getAnnotationsByClassId(StandardClassIds.Annotations.ExtensionFunctionType).isEmpty()) {
|
||||
builtIns.extensionFunctionTypeAnnotationConstructorCall()?.let {
|
||||
typeAnnotations += it
|
||||
}
|
||||
}
|
||||
}
|
||||
hasFlexibleNullability -> {
|
||||
builtIns.flexibleNullabilityAnnotationConstructorCall()?.let {
|
||||
typeAnnotations += it
|
||||
@@ -136,6 +131,18 @@ class Fir2IrTypeConverter(
|
||||
}
|
||||
}
|
||||
|
||||
if (isExtensionFunctionType && annotations.getAnnotationsByClassId(ExtensionFunctionType).isEmpty()) {
|
||||
builtIns.extensionFunctionTypeAnnotationConstructorCall()?.let {
|
||||
typeAnnotations += it
|
||||
}
|
||||
}
|
||||
|
||||
if (addRawTypeAnnotation) {
|
||||
builtIns.rawTypeAnnotationConstructorCall()?.let {
|
||||
typeAnnotations += it
|
||||
}
|
||||
}
|
||||
|
||||
for (attributeAnnotation in attributes.customAnnotations) {
|
||||
if (annotations.any { it.classId == attributeAnnotation.classId }) continue
|
||||
typeAnnotations += callGenerator.convertToIrConstructorCall(attributeAnnotation) as? IrConstructorCall ?: continue
|
||||
@@ -143,9 +150,19 @@ class Fir2IrTypeConverter(
|
||||
val expandedType = fullyExpandedType(session)
|
||||
val approximatedType = approximateType(expandedType)
|
||||
IrSimpleTypeImpl(
|
||||
irSymbol, !typeContext.definitelyNotNull && approximatedType.isMarkedNullable,
|
||||
approximatedType.typeArguments.map { it.toIrTypeArgument(typeContext) },
|
||||
typeAnnotations
|
||||
irSymbol,
|
||||
hasQuestionMark = !typeContext.definitelyNotNull && approximatedType.isMarkedNullable,
|
||||
arguments = approximatedType.typeArguments.map { it.toIrTypeArgument(typeContext) },
|
||||
annotations = typeAnnotations
|
||||
)
|
||||
}
|
||||
is ConeRawType -> {
|
||||
// Upper bound has star projections here, so we take lower one
|
||||
// (some reflection tests rely on this)
|
||||
lowerBound.toIrType(
|
||||
typeContext,
|
||||
hasFlexibleNullability = lowerBound.nullability != upperBound.nullability,
|
||||
addRawTypeAnnotation = true
|
||||
)
|
||||
}
|
||||
is ConeFlexibleType -> {
|
||||
|
||||
Reference in New Issue
Block a user