[FIR] Replace usages of FirExpression.typeRef with coneTypeOrNull

#KT-59855 Fixed
This commit is contained in:
Kirill Rakhman
2023-08-04 10:43:25 +02:00
committed by Space Team
parent f60d81097c
commit 8d7c5b375e
76 changed files with 538 additions and 565 deletions
@@ -271,16 +271,14 @@ abstract class AbstractAnnotationDeserializer(
val classId = nameResolver.getClassId(value.classId)
val lookupTag = classId.toLookupTag()
val referencedType = lookupTag.constructType(emptyArray(), isNullable = false)
val resolvedTypeRef = buildResolvedTypeRef {
type = StandardClassIds.KClass.constructClassLikeType(arrayOf(referencedType), false)
}
val resolvedType = StandardClassIds.KClass.constructClassLikeType(arrayOf(referencedType), false)
argumentList = buildUnaryArgumentList(
buildClassReferenceExpression {
classTypeRef = buildResolvedTypeRef { type = referencedType }
typeRef = resolvedTypeRef
coneTypeOrNull = resolvedType
}
)
typeRef = resolvedTypeRef
coneTypeOrNull = resolvedType
}
ENUM -> buildPropertyAccessExpression {
val classId = nameResolver.getClassId(value.classId)
@@ -300,7 +298,7 @@ abstract class AbstractAnnotationDeserializer(
name = entryName
}
if (enumEntrySymbol != null) {
typeRef = enumEntrySymbol.returnTypeRef
coneTypeOrNull = enumEntrySymbol.returnTypeRef.coneTypeOrNull
}
}
ARRAY -> {
@@ -309,9 +307,7 @@ abstract class AbstractAnnotationDeserializer(
argumentList = buildArgumentList {
value.arrayElementList.mapTo(arguments) { resolveValue(it, nameResolver) { expectedArrayElementType } }
}
typeRef = buildResolvedTypeRef {
type = expectedArrayElementType.createArrayType()
}
coneTypeOrNull = expectedArrayElementType.createArrayType()
}
}
@@ -320,6 +316,6 @@ abstract class AbstractAnnotationDeserializer(
}
private fun <T> const(kind: ConstantValueKind<T>, value: T, typeRef: FirResolvedTypeRef): FirConstExpression<T> {
return buildConstExpression(null, kind, value, setType = true).apply { this.replaceTypeRef(typeRef) }
return buildConstExpression(null, kind, value, setType = true).apply { this.replaceConeTypeOrNull(typeRef.coneType) }
}
}
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference
import org.jetbrains.kotlin.fir.resolve.providers.getClassDeclaredPropertySymbols
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
import org.jetbrains.kotlin.fir.types.ConeTypeProjection
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.fir.types.toLookupTag
@@ -44,9 +43,7 @@ fun FirEnumEntryDeserializedAccessExpression.toQualifiedPropertyAccessExpression
}
}
typeRef = buildResolvedTypeRef {
type = ConeClassLikeTypeImpl(
enumClassId.toLookupTag(), ConeTypeProjection.EMPTY_ARRAY, isNullable = false
)
}
coneTypeOrNull = ConeClassLikeTypeImpl(
enumClassId.toLookupTag(), ConeTypeProjection.EMPTY_ARRAY, isNullable = false
)
}
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.toEffectiveVisibility
import org.jetbrains.kotlin.fir.types.ConeLookupTagBasedType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.coneType
@@ -469,7 +470,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
proto.contextReceiverTypes(c.typeTable).mapTo(contextReceivers, ::loadContextReceiver)
}.apply {
initializer?.replaceTypeRef(returnTypeRef)
initializer?.replaceConeTypeOrNull(returnTypeRef.type)
this.versionRequirements = versionRequirements
replaceDeprecationsProvider(getDeprecationsProvider(c.session))
setLazyPublishedVisibility(c.session)
@@ -696,6 +697,6 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
}.toList()
}
private fun ProtoBuf.Type.toTypeRef(context: FirDeserializationContext): FirTypeRef =
private fun ProtoBuf.Type.toTypeRef(context: FirDeserializationContext): FirResolvedTypeRef =
context.typeDeserializer.typeRef(this)
}
@@ -108,7 +108,7 @@ class FirTypeDeserializer(
}
}
fun typeRef(proto: ProtoBuf.Type): FirTypeRef {
fun typeRef(proto: ProtoBuf.Type): FirResolvedTypeRef {
return buildResolvedTypeRef {
annotations += annotationDeserializer.loadTypeAnnotations(proto, nameResolver)
type = type(proto, annotations.computeTypeAttributes(moduleData.session, shouldExpandTypeAliases = false))
@@ -288,4 +288,4 @@ class FirTypeDeserializer(
val coneType = type(type)
return coneType.toTypeProjection(variance)
}
}
}