2ae2f09fee
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
46 lines
1.2 KiB
Kotlin
Vendored
46 lines
1.2 KiB
Kotlin
Vendored
|
|
// WITH_STDLIB
|
|
|
|
import kotlinx.serialization.*
|
|
import kotlinx.serialization.json.*
|
|
import kotlinx.serialization.internal.*
|
|
|
|
enum class Plain {
|
|
A, B
|
|
}
|
|
|
|
@Serializable enum class WithNames {
|
|
@SerialName("A") ENTRY1,
|
|
@SerialName("B") ENTRY2
|
|
}
|
|
|
|
@Serializable
|
|
class Holder(val p: Plain, val w: WithNames)
|
|
|
|
@OptIn(InternalSerializationApi::class)
|
|
fun testSerializers(): String {
|
|
val cs = (Holder.serializer() as GeneratedSerializer<*>).childSerializers()
|
|
val str1 = cs[0].toString()
|
|
if (!str1.contains("kotlinx.serialization.internal.EnumSerializer")) return str1
|
|
|
|
/**
|
|
* Serialization 1.5.0+ have runtime factories to create EnumSerializer instead of synthetic $serializer, saving bytecode
|
|
* and bringing consistency.
|
|
*/
|
|
// val str2 = cs[1].toString()
|
|
// if (!str2.contains("kotlinx.serialization.internal.EnumSerializer")) return str2
|
|
return "OK"
|
|
}
|
|
|
|
fun testSerialization(previous: String): String {
|
|
if (previous != "OK") return previous
|
|
val h = Holder(Plain.B, WithNames.ENTRY1)
|
|
val s = Json.encodeToString(Holder.serializer(), h)
|
|
if (s != """{"p":"B","w":"A"}""") return s
|
|
return "OK"
|
|
}
|
|
|
|
fun box(): String {
|
|
return testSerialization(testSerializers())
|
|
}
|