Fixed serialization with custom serializer for parametrized sealed class

#KT-50764 Fixed
#KT-50718 Fixed
Fixes Kotlin/kotlinx.serialization#1705
This commit is contained in:
Sergey.Shanshin
2022-01-25 19:04:55 +03:00
committed by Space
parent acced31bb2
commit aa1700f3e7
@@ -1135,9 +1135,10 @@ interface IrBuilderExtension {
} ?: return null
val adjustedArgs: List<IrExpression> =
if (baseClass.descriptor.isSealed() || baseClass.descriptor.modality == Modality.ABSTRACT) {
// if typeArgs.size == args.size then the serializer is custom - we need to use the actual serializers from the arguments
if ((typeArgs.size != args.size) && (baseClass.descriptor.isSealed() || baseClass.descriptor.modality == Modality.ABSTRACT)) {
val serializer = findStandardKotlinTypeSerializer(baseClass.module, context.irBuiltIns.unitType.toKotlinType())!!
// workaround for sealed and classes - the `serializer` function expects non-null serializers, but does not use them, so serializers of any type can be passed
// workaround for sealed and abstract classes - the `serializer` function expects non-null serializers, but does not use them, so serializers of any type can be passed
List(baseClass.typeParameters.size) { irGetObject(serializer) }
} else {
args