You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[KxSerialization] Fixed initialization error for keep generated serializer feature with sealed classes
When the heir of a sealed class contains this sealed class as a property, cyclic initialization occurs due to the fact that the SealedClassSerializer in the constructor accesses all passed subclass serializers.
Initialization order:
Parent Sealed class serializer
\/
Create instance of SealedClassSerializer for Parent Sealed
\/
Access subclass serializer in constructor of SealedClassSerializer
\/
Call ChildClass.Compaion.generatedSerializer()
\/
Init ChildClass
\/
cache child serializers of ChildClass
\/
Create instance of SealedClassSerializer for Parent Sealed ---> /\
Fixes #KT-70516
Merge-request: KT-MR-17421
Merged-by: Sergei Shanshin <[email protected]>
Copy file name to clipboardExpand all lines: plugins/kotlinx-serialization/kotlinx-serialization.backend/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/BaseIrGenerator.kt
+12-3Lines changed: 12 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -464,13 +464,15 @@ abstract class BaseIrGenerator(private val currentClass: IrClass, final override
// to avoid a cyclical dependency between the serializer cache and the cache of child serializers,
476
478
// the class should not cache its serializer as a child
@@ -486,14 +488,21 @@ abstract class BaseIrGenerator(private val currentClass: IrClass, final override
486
488
val serializer = getIrSerialTypeInfo(property, compilerContext).serializer ?:returnnull
487
489
if (serializer.owner.kind ==ClassKind.OBJECT) returnnull
488
490
489
-
return serializerInstance(
491
+
// disable caching for sealed serializer because of initialization loop, see https://github.com/Kotlin/kotlinx.serialization/issues/2759
492
+
if (hasKeepGeneratedSerializerAnnotation && serializer.owner.classId == sealedSerializerId) {
0 commit comments