K2: fix logic for supertypes annotation deserialization

This commit is contained in:
pyos
2022-11-09 17:42:04 +01:00
committed by Space Team
parent 456fe858a0
commit a968193349
4 changed files with 19 additions and 23 deletions
@@ -3,7 +3,7 @@
}
public abstract interface Foo<T : R|@R|test/A|() kotlin/Number|> : R|java/io/Serializable| {
public abstract interface Foo<T : R|@R|test/A|() kotlin/Number|> : R|@R|test/A|() java/io/Serializable| {
public abstract fun <E, F : R|E|> bar(): R|kotlin/Unit|
}
@@ -123,14 +123,7 @@ fun deserializeClassToSymbol(
val typeDeserializer = context.typeDeserializer
val classDeserializer = context.memberDeserializer
val superTypesDeserialized = classProto.supertypes(context.typeTable).map { supertypeProto ->
typeDeserializer.simpleType(supertypeProto, ConeAttributes.Empty)
}
superTypesDeserialized.mapNotNullTo(superTypeRefs) {
if (it == null) return@mapNotNullTo null
buildResolvedTypeRef { type = it }
}
classProto.supertypes(context.typeTable).mapTo(superTypeRefs, typeDeserializer::typeRef)
addDeclarations(
classProto.functionList.map {
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.ConeLookupTagBasedType
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.computeTypeAttributes
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
@@ -635,11 +634,6 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
}.toList()
}
private fun ProtoBuf.Type.toTypeRef(context: FirDeserializationContext): FirTypeRef {
return buildResolvedTypeRef {
annotations += context.annotationDeserializer.loadTypeAnnotations(this@toTypeRef, context.nameResolver)
val attributes = annotations.computeTypeAttributes(context.session)
type = context.typeDeserializer.type(this@toTypeRef, attributes)
}
}
private fun ProtoBuf.Type.toTypeRef(context: FirDeserializationContext): FirTypeRef =
context.typeDeserializer.typeRef(this)
}
@@ -106,13 +106,22 @@ class FirTypeDeserializer(
}
}
fun type(proto: ProtoBuf.Type): ConeKotlinType {
val annotations = annotationDeserializer.loadTypeAnnotations(proto, nameResolver)
val attributes = annotations.computeTypeAttributes(moduleData.session)
return type(proto, attributes)
fun typeRef(proto: ProtoBuf.Type): FirTypeRef {
return buildResolvedTypeRef {
annotations += annotationDeserializer.loadTypeAnnotations(proto, nameResolver)
type = type(proto, annotations.computeTypeAttributes(moduleData.session))
}
}
fun type(proto: ProtoBuf.Type, attributes: ConeAttributes): ConeKotlinType {
private fun attributesFromAnnotations(proto: ProtoBuf.Type) =
annotationDeserializer.loadTypeAnnotations(proto, nameResolver)
.computeTypeAttributes(moduleData.session)
fun type(proto: ProtoBuf.Type): ConeKotlinType {
return type(proto, attributesFromAnnotations(proto))
}
private fun type(proto: ProtoBuf.Type, attributes: ConeAttributes): ConeKotlinType {
if (proto.hasFlexibleTypeCapabilitiesId()) {
val lowerBound = simpleType(proto, attributes)
val upperBound = simpleType(proto.flexibleUpperBound(typeTable)!!, attributes)
@@ -145,7 +154,7 @@ class FirTypeDeserializer(
fun FirClassLikeSymbol<*>.typeParameters(): List<FirTypeParameterSymbol> =
(fir as? FirTypeParameterRefsOwner)?.typeParameters?.map { it.symbol }.orEmpty()
fun simpleType(proto: ProtoBuf.Type, attributes: ConeAttributes): ConeSimpleKotlinType? {
private fun simpleType(proto: ProtoBuf.Type, attributes: ConeAttributes): ConeSimpleKotlinType? {
val constructor = typeSymbol(proto) ?: return null
if (constructor is ConeTypeParameterLookupTag) {
return ConeTypeParameterTypeImpl(constructor, isNullable = proto.nullable).let {