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

23 lines
807 B
Kotlin
Vendored

// WITH_STDLIB
import kotlinx.serialization.*
import kotlinx.serialization.json.*
@Serializable
class SomeClass(val i: Int)
fun box(): String {
val targetString = """{"i":42}"""
val serializer = SomeClass.Companion.serializer()
val descriptor = serializer.descriptor
if (descriptor.toString() != "SomeClass(i: kotlin.Int)") return "Incorrect SerialDescriptor.toString(): $descriptor"
val instance = SomeClass(42)
val string = Json.encodeToString(serializer, instance)
if (string != targetString) return "Incorrect serialization result: expected $targetString, got $string"
val instance2 = Json.decodeFromString(serializer, string)
if (instance2.i != instance.i) return "Incorrect deserialization result: expected ${instance.i}, got ${instance2.i}"
return "OK"
}