diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt index 1f42eff1af0..56695aac149 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt @@ -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) } diff --git a/compiler/testData/codegen/box/syntheticAccessors/inlineInOtherClass.kt b/compiler/testData/codegen/box/syntheticAccessors/inlineInOtherClass.kt new file mode 100644 index 00000000000..9664410fb44 --- /dev/null +++ b/compiler/testData/codegen/box/syntheticAccessors/inlineInOtherClass.kt @@ -0,0 +1,7 @@ +class A { + private inline fun f() = g() + private fun g() = "OK" + fun h() = { f() } +} + +fun box() = A().h()() diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index b73db0c1a9c..23cf7a0dbc6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index e10f87b16ba..a3890549ee4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index fc25daf5764..9095f24482b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index abddeb42d19..e1998f4fc80 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -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"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 2c1ae4b712e..b1590521a61 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -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");