JVM_IR: fix synthetic accessor generation (again)
Turns out private inline functions *can* be called from other classes.
This commit is contained in:
+5
-3
@@ -435,11 +435,13 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
|
||||
private fun IrDeclaration.getAccessContext(withSuper: Boolean): IrDeclarationContainer? = when {
|
||||
this is IrDeclarationContainer -> this
|
||||
// Accesses from public inline functions can actually be anywhere. For protected inline functions
|
||||
// calling methods on `super` we need an accessor to satisfy INVOKESPECIAL constraints.
|
||||
this is IrFunction && isInline && !visibility.isPrivate && (withSuper || !visibility.isProtected) -> null
|
||||
// For inline lambdas, we can navigate to the only call site directly.
|
||||
this in inlineLambdaToCallSite -> inlineLambdaToCallSite[this]?.getAccessContext(withSuper)
|
||||
// Accesses from inline functions can actually be anywhere; even private inline functions can be
|
||||
// inlined into a different class, e.g. a callable reference. For protected inline functions
|
||||
// calling methods on `super` we also need an accessor to satisfy INVOKESPECIAL constraints.
|
||||
// TODO scan nested classes for calls to private inline functions?
|
||||
this is IrFunction && isInline -> null
|
||||
else -> (parent as? IrDeclaration)?.getAccessContext(withSuper)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class A {
|
||||
private inline fun f() = g()
|
||||
private fun g() = "OK"
|
||||
fun h() = { f() }
|
||||
}
|
||||
|
||||
fun box() = A().h()()
|
||||
+5
@@ -24922,6 +24922,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/inline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineInOtherClass.kt")
|
||||
public void testInlineInOtherClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/inlineInOtherClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmField.kt")
|
||||
public void testJvmField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/jvmField.kt");
|
||||
|
||||
+5
@@ -24922,6 +24922,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/inline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineInOtherClass.kt")
|
||||
public void testInlineInOtherClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/inlineInOtherClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmField.kt")
|
||||
public void testJvmField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/jvmField.kt");
|
||||
|
||||
+5
@@ -23822,6 +23822,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/inline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineInOtherClass.kt")
|
||||
public void testInlineInOtherClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/inlineInOtherClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmField.kt")
|
||||
public void testJvmField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/jvmField.kt");
|
||||
|
||||
Generated
+5
@@ -19052,6 +19052,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/inline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineInOtherClass.kt")
|
||||
public void testInlineInOtherClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/inlineInOtherClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt10047.kt")
|
||||
public void testKt10047() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
|
||||
|
||||
+5
@@ -20207,6 +20207,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/inline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineInOtherClass.kt")
|
||||
public void testInlineInOtherClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/inlineInOtherClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt10047.kt")
|
||||
public void testKt10047() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
|
||||
|
||||
Reference in New Issue
Block a user