JVM_IR: remap calls to protected @JvmStatic in companions

Protected functions on unrelated classes cannot be called from outside
the current package, so in general, we can only call the static proxy,
not the original companion method.

This has an ABI compatibility implication in that removing `@JvmStatic`
from a protected companion method will require recompiling Kotlin use
sites (of course, this is already source- and binary-incompatible from
Java perspective).

 #KT-12063 Fixed
This commit is contained in:
pyos
2021-03-19 11:08:56 +01:00
committed by Alexander Udalov
parent 85aa6383ad
commit a518a9407d
7 changed files with 216 additions and 130 deletions
@@ -0,0 +1,21 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM
// WITH_RUNTIME
// FILE: 1.kt
package a
open class A {
companion object {
@JvmStatic // Required to be accessible from subclasses of A in other packages.
protected fun foo() = "OK"
}
}
// FILE: 2.kt
import a.*
class B : A() {
fun bar() = foo() // calls static A.foo(), not inaccessible A.Companion.foo()
}
fun box() = B().bar()