kotlinx.serialization: Support @Serializable on sealed interfaces.
Interfaces (regular and sealed) are by default polymorphic. To benefit from sealing (i.e. knowledge of all inheritors in compile-time), @Serializable annotation may be added on sealed interface, generating the same serializer that can be used for sealed classes. Synthetic nested classes are not generated in DEFAULT_IMPLS mode because it causes problems when adding a synthetic companion to an interface. Fixes https://github.com/Kotlin/kotlinx.serialization/issues/1576
This commit is contained in:
@@ -105,12 +105,14 @@ public abstract class ClassBodyCodegen extends MemberCodegen<KtPureClassOrObject
|
||||
}
|
||||
|
||||
// Generate synthetic nested classes
|
||||
Collection<DeclarationDescriptor> classifiers = descriptor
|
||||
.getUnsubstitutedMemberScope()
|
||||
.getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS, MemberScope.Companion.getALL_NAME_FILTER());
|
||||
for (DeclarationDescriptor memberDescriptor : classifiers) {
|
||||
if (memberDescriptor instanceof SyntheticClassOrObjectDescriptor) {
|
||||
genSyntheticClassOrObject((SyntheticClassOrObjectDescriptor) memberDescriptor);
|
||||
if (kind != OwnerKind.DEFAULT_IMPLS) {
|
||||
Collection<DeclarationDescriptor> classifiers = descriptor
|
||||
.getUnsubstitutedMemberScope()
|
||||
.getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS, MemberScope.Companion.getALL_NAME_FILTER());
|
||||
for (DeclarationDescriptor memberDescriptor : classifiers) {
|
||||
if (memberDescriptor instanceof SyntheticClassOrObjectDescriptor) {
|
||||
genSyntheticClassOrObject((SyntheticClassOrObjectDescriptor) memberDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user