Skip to content

Commit

Permalink
Fixed serialization with custom serializer for parametrized sealed class
Browse files Browse the repository at this point in the history
#KT-50764 Fixed
#KT-50718 Fixed
Fixes Kotlin/kotlinx.serialization#1705

(cherry picked from commit aa1700f)
  • Loading branch information
shanshin committed Jan 26, 2022
1 parent ced1112 commit fd2d42a
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fd2d42a

Please sign in to comment.