JVM IR: generate private @JvmStatic functions as in old backend

#KT-46181 Fixed
This commit is contained in:
Alexander Udalov
2021-09-02 22:43:52 +02:00
parent ed035d99ab
commit 9a472c418f
13 changed files with 184 additions and 39 deletions
@@ -0,0 +1,35 @@
// WITH_RUNTIME
// For a private @JvmStatic function `f` in `A.Companion`, we generate:
// 1) private instance method `f` in `A.Companion`, with the actual implementation;
// 2) public static method `access$f` in `A.Companion` which calls `A.Companion.f`;
// 3) private static method `f` in `A` which calls `A.Companion.access$f`.
// (which is basically the same as all @JvmStatic companion functions, except that we also need an accessor here.)
//
// This might seem like an overkill, but there are actually some use cases, namely private static helpers for JNI (see KT-46181).
class A {
companion object {
@JvmStatic
private fun f(p: Int) {}
@JvmStatic
private val x = ""
private var xx: String
@JvmStatic get() = ""
@JvmStatic set(value) {}
}
}
object O {
@JvmStatic
private fun g(q: Int) {}
@JvmStatic
private val y = ""
private var yy: String
@JvmStatic get() = ""
@JvmStatic set(value) {}
}