Files
kotlin-fork/plugins/kotlinx-serialization/testData/jdk11BoxIr/kt57647.kt
T
Sergey.Shanshin d8d643b7d7 [KxSerialization] Fix "IllegalAccessError: Update to static final field"
Fixes #KT-57647

For value classes, if you add code to companion anonymous init block in IR, it will be executed in the instance constructor. This causes an error when initializing static fields, because writing to them can only occur from the <clinit> method.

The solution is to transfer the static field initialization code from an anonymous init block to the IR initializer of this field

Merge-request: KT-MR-9633
Merged-by: Sergey Shanshin <Sergey.Shanshin@jetbrains.com>
2023-04-21 12:37:32 +00:00

33 lines
503 B
Kotlin
Vendored

// TARGET_BACKEND: JVM_IR
// WITH_STDLIB
// IGNORE_DEXING
import kotlinx.serialization.*
import java.util.UUID
@Serializable
@JvmInline
value class Id(val id: @Contextual UUID) {
companion object {
fun random() = Id(UUID.randomUUID())
}
}
@Serializable
@JvmInline
value class Parametrized<T: Any>(val l: List<T>)
fun pageMain () {
val id: Id = Id.random()
println(id)
}
fun box(): String {
println(System.getProperty("java.version"))
pageMain()
return "OK"
}