JVM_IR: avoid redundant accessors in private inline funs
Their call sites are all in the same file, so we can check whether the declarations used in the inline function are accessible from all the places where it will be inlined. #KT-48736 Fixed
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: test/J.java
|
||||
package test;
|
||||
|
||||
public class J {
|
||||
String packagePrivate = "OK";
|
||||
}
|
||||
|
||||
// FILE: test/main.kt
|
||||
package test
|
||||
|
||||
object O {
|
||||
fun box() = privateInline()
|
||||
|
||||
// no accessor needed - the only call site is in the same package
|
||||
private inline fun privateInline(): String = J().packagePrivate
|
||||
}
|
||||
|
||||
fun box() = O.box()
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package a
|
||||
|
||||
open class A {
|
||||
protected fun protectedFun(): String = "OK"
|
||||
}
|
||||
|
||||
class BSamePackage: A() {
|
||||
// known to only be called within `BSamePackage`, so accessors are redundant
|
||||
private inline fun test(): String = protectedFun()
|
||||
|
||||
fun onlyTestCallSite() = test()
|
||||
}
|
||||
|
||||
// JVM_TEMPLATES
|
||||
// 2 INVOKESTATIC a/BSamePackage.access
|
||||
// JVM_IR_TEMPLATES
|
||||
// 0 INVOKESTATIC a/BSamePackage.access
|
||||
Reference in New Issue
Block a user