Skip to content

SerialInfo annotations on enum classes are not saved in 1.7.20+ #2121

@sandwwraith

Description

@sandwwraith

Describe the bug

SerialInfo annotations on enum classes (not members!) were saved up to Kotlin 1.7.10, but starting from 1.7.20 they're lost.

To Reproduce

@SerialInfo
@Target(AnnotationTarget.CLASS, AnnotationTarget.PROPERTY)
annotation class A(val i: Int)

@A(1)
@Serializable
enum class Baz {
    @A(2) X, @A(3) Y
}

@Test
fun enumTest() {
    val d = Baz.serializer().descriptor
    println(d.annotations)
    println(d.getElementAnnotations(0))
    println(d.getElementAnnotations(1))
}

Expected behavior

On 1.7.10 test printed:

[kotlinx.serialization.A$Impl@65b5b5ed]
[kotlinx.serialization.A$Impl@795eddda]
[kotlinx.serialization.A$Impl@c6bf8d9]

On 1.7.20 test prints:

[]
[kotlinx.serialization.A$Impl@6bc85459]
[kotlinx.serialization.A$Impl@64a67067]

Reason:

In 1.7.20, factory function

internal fun <T : Enum<T>> createMarkedEnumSerializer(
is used instead of generated $serializer for enums. It doesn't have slots for class-level annotations.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions