Reflection: improve and optimize kotlinFunction/kotlinProperty

- Make the implementations very similar, to fix KT-54833 where the
  companion object case was forgotten for kotlinProperty.
- Optimize both functions to look up the function/property by name
  first, to cover the most probable case when the JVM name of a
  declaration is equal to its Kotlin name. This fixes KT-55937.

 #KT-54833 Fixed
 #KT-55937 Fixed
This commit is contained in:
Alexander Udalov
2023-01-16 22:41:47 +01:00
parent aa7b4cfbe6
commit c58314fddf
9 changed files with 225 additions and 14 deletions
@@ -0,0 +1,16 @@
// WITH_REFLECT
// TARGET_BACKEND: JVM
import kotlin.reflect.KProperty1
import kotlin.reflect.jvm.kotlinProperty
class C {
companion object {
val x = "OK"
}
}
fun box(): String {
val f = C::class.java.getDeclaredField("x").kotlinProperty as KProperty1<C.Companion, String>
return f.get(C.Companion)
}