JVM IR: add jvmLocalClassExtractionPhase to lift out local classes from initializers
Otherwise a local class in a field initializer or anonymous init block is copied into each constructor of the containing class (because InitializersLowering calls deepCopy). Since the code structure no longer resembles the original source code here, record a custom EnclosingMethod mapping before moving such classes, and use it in codegen.
This commit is contained in:
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: A.kt
|
||||
|
||||
class A {
|
||||
val o = object {
|
||||
@JvmName("jvmGetO")
|
||||
fun getO(): String = "O"
|
||||
}
|
||||
|
||||
val k = object {
|
||||
@get:JvmName("jvmGetK")
|
||||
val k: String = "K"
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: B.kt
|
||||
|
||||
import kotlin.reflect.full.*
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val obj1 = a.o
|
||||
val o = obj1::class.declaredMemberFunctions.single().call(obj1) as String
|
||||
val obj2 = a.k
|
||||
val k = obj2::class.declaredMemberProperties.single().call(obj2) as String
|
||||
return o + k
|
||||
}
|
||||
Reference in New Issue
Block a user