Files
kotlin-fork/plugins/kotlinx-serialization/testData/firMembers/defaultProperties.kt
T
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

29 lines
910 B
Kotlin
Vendored

// WITH_STDLIB
import kotlinx.serialization.*
import kotlinx.serialization.json.*
@Serializable
data class SomeClass(val ctor: Int = 42, val ctorDependent: Int = ctor + 1) {
var body: String = ""
var bodyDependent = ctor + 2
}
fun test(targetString: String): String {
val json = Json { encodeDefaults = true }
val c = SomeClass(1).apply { body = "x" }
val s = json.encodeToString(SomeClass.serializer(), c)
if (s != targetString) return s
val i2 = json.decodeFromString(SomeClass.serializer(), "{}")
if (i2.ctor != 42) return "Incorrect default ctor"
if (i2.ctorDependent != 43) return "Incorrect default ctorDependent"
if (i2.body != "") return "Incorrect default body"
if (i2.bodyDependent != 44) return "Incorrect default bodyDependent"
return "OK"
}
fun box(): String {
return test("""{"ctor":1,"ctorDependent":2,"body":"x","bodyDependent":3}""")
}