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
38 lines
1.0 KiB
Kotlin
Vendored
38 lines
1.0 KiB
Kotlin
Vendored
// WITH_STDLIB
|
|
|
|
/**
|
|
* write$Self and synthetic constructor are required for correct serialization and deserialization of private fields,
|
|
* otherwise inaccessible from e.g. Derived.$serializer.serialize().
|
|
* This test verifies that.
|
|
*/
|
|
import kotlinx.serialization.*
|
|
import kotlinx.serialization.json.*
|
|
|
|
@Serializable
|
|
open class Parent(private val ctor: Int) {
|
|
private var body: String = "42"
|
|
|
|
fun checkDeser(c: Int, b: String): String {
|
|
if (this.ctor != c) return "Ctor : ${this.ctor}"
|
|
if (this.body != b) return "Body : ${this.body}"
|
|
return "OK"
|
|
}
|
|
}
|
|
|
|
@Serializable
|
|
class Derived: Parent(42)
|
|
|
|
fun test(targetString: String): String {
|
|
val c = Derived()
|
|
val j = Json { encodeDefaults = true }
|
|
val s = j.encodeToString(Derived.serializer(), c)
|
|
if (s != targetString) return s
|
|
val d = j.decodeFromString(Derived.serializer(), """{"ctor":43,"body":"43"}""")
|
|
return d.checkDeser(43, "43")
|
|
return "OK"
|
|
}
|
|
|
|
fun box(): String {
|
|
return test("""{"ctor":42,"body":"42"}""")
|
|
}
|