Files
kotlin-fork/compiler/testData/codegen/box/fieldRename/jvmFieldNoClash1.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

24 lines
678 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_STDLIB
// In the old JVM backend, FieldOwnerContext is sensitive to the order of properties which it invents name for. Companion object properties
// are usually the first, so A.Companion.x here gets the name "x". After that it tries to invent a new name for A.x but fails because
// @JvmField-annotated properties cannot be renamed, which leads to a JVM declaration clash error.
// IGNORE_BACKEND: JVM
class A {
@JvmField
val x = "outer"
companion object {
val x = "companion"
}
}
fun box(): String {
if (A().x != "outer") return "Fail outer"
if (A.x != "companion") return "Fail companion"
return "OK"
}