diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index 2ea2e3a3b16..dc9b998bb5c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -253,10 +253,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { if (!(myClass instanceof KtClass)) return; if (!descriptor.isInline()) return; - CodegenContext parentContext = context.getParentContext(); - assert parentContext != null : "Parent context of inline class declaration should not be null"; - - ClassContext erasedInlineClassContext = parentContext.intoWrapperForErasedInlineClass(descriptor, state); + ClassContext erasedInlineClassContext = context.intoWrapperForErasedInlineClass(descriptor, state); new ErasedInlineClassBodyCodegen((KtClass) myClass, erasedInlineClassContext, v, state, this).generate(); } @@ -270,7 +267,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { if (inlinedValue == null) return; Type valueType = typeMapper.mapType(inlinedValue.getType()); - SimpleFunctionDescriptor functionDescriptor = InlineClassDescriptorResolver.INSTANCE.createUnboxFunctionDescriptor(this.descriptor); + SimpleFunctionDescriptor functionDescriptor = InlineClassDescriptorResolver.createUnboxFunctionDescriptor(this.descriptor); assert functionDescriptor != null : "FunctionDescriptor for unbox method should be not null during codegen"; functionCodegen.generateMethod( diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/context/CodegenContext.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/context/CodegenContext.java index 76af3fa2dac..d7f1ed2cfce 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/context/CodegenContext.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/context/CodegenContext.java @@ -393,12 +393,16 @@ public abstract class CodegenContext { public CodegenContext findParentContextWithDescriptor(DeclarationDescriptor descriptor) { CodegenContext c = this; while (c != null) { - if (c.getContextDescriptor() == descriptor) break; + if (!c.shouldSkipThisContextInHierarchy() && c.getContextDescriptor() == descriptor) break; c = c.getParentContext(); } return c; } + private boolean shouldSkipThisContextInHierarchy() { + return getContextKind() == OwnerKind.ERASED_INLINE_CLASS; + } + @NotNull private PropertyDescriptor getPropertyAccessor( @NotNull PropertyDescriptor propertyDescriptor, diff --git a/compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt b/compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt new file mode 100644 index 00000000000..0421d347d7f --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +InlineClasses +// IGNORE_BACKEND: JVM_IR + +inline class R(private val r: Int) { + fun test() = pf() + + companion object { + private fun pf() = "OK" + } +} + +fun box() = R(0).test() \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 55c4bc081f1..1ec73e99445 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -12120,6 +12120,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/membersAccess"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("toPrivateCompanionFun.kt") + public void testToPrivateCompanionFun() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt"); + } + @TestMetadata("toPrivateCompanionVal.kt") public void testToPrivateCompanionVal() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 0f934417c34..6bb792ee994 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -12120,6 +12120,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/membersAccess"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("toPrivateCompanionFun.kt") + public void testToPrivateCompanionFun() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt"); + } + @TestMetadata("toPrivateCompanionVal.kt") public void testToPrivateCompanionVal() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 723c153537a..e937b3c2958 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -12125,6 +12125,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/membersAccess"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); } + @TestMetadata("toPrivateCompanionFun.kt") + public void testToPrivateCompanionFun() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt"); + } + @TestMetadata("toPrivateCompanionVal.kt") public void testToPrivateCompanionVal() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java index 83e2317b80d..1f4b069ca38 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java @@ -10660,6 +10660,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/membersAccess"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true); } + @TestMetadata("toPrivateCompanionFun.kt") + public void testToPrivateCompanionFun() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt"); + } + @TestMetadata("toPrivateCompanionVal.kt") public void testToPrivateCompanionVal() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.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 9fab1a980fb..5a2982faa50 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 @@ -11705,6 +11705,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/membersAccess"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("toPrivateCompanionFun.kt") + public void testToPrivateCompanionFun() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt"); + } + @TestMetadata("toPrivateCompanionVal.kt") public void testToPrivateCompanionVal() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt");