Files
Sergey.Shanshin 2ae2f09fee [FIR] Fixed phase for FirCompanionGenerationProcessor to COMPANION_GENERATION
Phase COMPILER_REQUIRED_ANNOTATIONS causes errors in the kotlinx serialization tests:

org.jetbrains.kotlin.fir.symbols.FirLazyResolveContractViolationException: `lazyResolveToPhase(COMPILER_REQUIRED_ANNOTATIONS)` cannot be called from a transformer with a phase COMPILER_REQUIRED_ANNOTATIONS.
`lazyResolveToPhase` can be called only from a transformer with a phase which is strictly greater than a requested phase;
 i.e., `lazyResolveToPhase(A)` may be only called from a lazy transformer with a phase B, where A < B. This is a contract of lazy resolve
2024-02-12 15:54:11 +00:00

52 lines
1.3 KiB
Kotlin
Vendored

// WITH_STDLIB
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.json.*
@Serializable
sealed interface I
@Serializable
sealed class X: I {
private var x = "X"
fun exposeX() = x
}
@Serializable
abstract class Y: X() {
private var y = "Y"
fun exposeY() = y
}
@Serializable
class Bottom: Y()
fun testData(results: String): String {
if (results != "OK") return results
val serial = Bottom.serializer()
val j = Json { encodeDefaults = true }
val s = j.encodeToString(serial, Bottom())
if (s != """{"x":"X","y":"Y"}""") return "Incorrect encoding: $s"
val decoded = j.decodeFromString(serial, """{"x":"1","y":"2"}""")
if (decoded.exposeX() != "1") return "Incorrect X"
if (decoded.exposeY() != "2") return "Incorrect Y"
return "OK"
}
@OptIn(ExperimentalSerializationApi::class)
fun testKinds(): String {
if (I.serializer().descriptor.kind != PolymorphicKind.SEALED) return "Not sealed: I"
if (X.serializer().descriptor.kind != PolymorphicKind.SEALED) return "Not sealed: X"
if (Y.serializer().descriptor.kind != PolymorphicKind.OPEN) return "Not polymorphic: Y"
val serial = Bottom.serializer()
if (serial.descriptor.kind != StructureKind.CLASS) return "Not class: Bottom"
return "OK"
}
fun box(): String {
return testData(testKinds())
}