Files
kotlin-fork/plugins/kotlin-serialization/kotlin-serialization-compiler/testData/boxIr/sealedInterfaces.kt
T
Leonid Startsev de128a5406 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
2021-12-01 14:14:47 +00:00

37 lines
646 B
Kotlin
Vendored

// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM_IR
// WITH_RUNTIME
package a
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlin.test.assertEquals
interface I
sealed interface SI
@Serializable
sealed interface SSI
@Serializable
class Holder(
val i: I,
val si: SI,
val ssi: SSI
)
fun SerialDescriptor.checkKind(index: Int, kind: String) {
assertEquals(kind, getElementDescriptor(index).kind.toString())
}
fun box(): String {
val desc = Holder.serializer().descriptor
desc.checkKind(0, "OPEN")
desc.checkKind(1, "OPEN")
desc.checkKind(2, "SEALED")
return "OK"
}