[JVM IR] Copy metadata in IrFieldBuilder.

This fixes an issue with lateinit properties where the metadata from
the original field was not copied to the nullable field in
LateinitLowering. Also consolidated related tests.
This commit is contained in:
Mark Punzalan
2020-01-23 13:59:06 -08:00
committed by Alexander Udalov
parent f5f25224b0
commit e226561150
12 changed files with 109 additions and 66 deletions
@@ -0,0 +1,33 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.reflect.jvm.*
import kotlin.test.*
class K {
lateinit var value: String
}
fun box(): String {
val p = K::value
assertNotNull(p.javaField, "Fail p field")
val getter = p.javaGetter!!
val setter = p.javaSetter!!
assertEquals(K::class.java.getMethod("getValue"), getter)
assertEquals(K::class.java.getMethod("setValue", String::class.java), setter)
assertNull(p.getter.javaConstructor)
assertNull(p.setter.javaConstructor)
val k = K()
assertFails("Fail k getter") { getter.invoke(k) } // lateinit not yet initialized
setter.invoke(k, "foo")
assertEquals("foo", getter.invoke(k), "Fail k setter")
return "OK"
}