Handle situation where KSerializer is absent from immediate supertypes

of the class used in @UseSerializers: Use methods to receive
full list of supertypes.

K1 supertypes() call returned all supertypes, while
IrClass.supertypes and FirClassSymbol.resolvedSuperTypes return only immediate ones.

This lead to a difference in behavior between K1 and K2, and regression
after plugin backend was rewritten from descriptors to IR.

#KT-55340 Fixed
This commit is contained in:
Leonid Startsev
2022-12-07 13:57:19 +01:00
committed by Space Team
parent c011f0c374
commit 1c4614e93b
7 changed files with 98 additions and 9 deletions
@@ -82,10 +82,10 @@ abstract class BaseIrGenerator(private val currentClass: IrClass, final override
}
val additionalSerializersInScopeOfCurrentFile: Map<Pair<IrClassSymbol, Boolean>, IrClassSymbol> by lazy {
getClassListFromFileAnnotation(SerializationAnnotations.additionalSerializersFqName,)
getClassListFromFileAnnotation(SerializationAnnotations.additionalSerializersFqName)
.associateBy(
{ serializerSymbol ->
val kotlinType = (serializerSymbol.owner.superTypes.find(IrType::isKSerializer) as? IrSimpleType)?.arguments?.firstOrNull()?.typeOrNull
val kotlinType = getAllSubstitutedSupertypes(serializerSymbol.owner).find(IrType::isKSerializer)?.arguments?.firstOrNull()?.typeOrNull
val classSymbol = kotlinType?.classOrNull
?: error("Argument for ${SerializationAnnotations.additionalSerializersFqName} does not implement KSerializer or does not provide serializer for concrete type")
classSymbol to kotlinType.isNullable()