JVM IR: rename private fields for properties with same name

This is needed to get rid of the code that appends "$companion" to
properties moved from companion, because it caused inconsistencies in
the ABI and in JVM signatures stored in the metadata
This commit is contained in:
Alexander Udalov
2019-02-08 16:13:39 +01:00
parent b4571fd548
commit 4487c7a988
9 changed files with 220 additions and 15 deletions
+13 -6
View File
@@ -16,14 +16,21 @@ public open class TestDelegate<T: Any>(private val initializer: () -> T) {
}
}
class A {}
class B {}
class A
class B
class C
class D
public val A.s: String by TestDelegate( {"OK2"})
public val B.s: String by TestDelegate( {"OK"})
public val A.s: String by TestDelegate({"A"})
public val B.s: String by TestDelegate({"B"})
public val C.s: String by TestDelegate({"C"})
public val D.s: String by TestDelegate({"D"})
fun box() : String {
if (A().s != "OK2") return "fail1"
if (A().s != "A") return "Fail A"
if (B().s != "B") return "Fail B"
if (C().s != "C") return "Fail C"
if (D().s != "D") return "Fail D"
return B().s
return "OK"
}
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// 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"
}
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
class A {
val x = "outer"
val y = "outer"
companion object {
@JvmField
val x = "companion"
const val y = "companion"
}
}
fun box(): String {
if (A().x != "outer") return "Fail outer x"
if (A().y != "outer") return "Fail outer y"
if (A.x != "companion") return "Fail companion x"
if (A.y != "companion") return "Fail companion y"
return "OK"
}