diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index c1e2a596125..832004ef253 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -2862,7 +2862,7 @@ public class ExpressionCodegen extends KtVisitor impleme } } - private static CodegenContext getContextForCompanionObjectAccessorIfRequiredOrNull( + private CodegenContext getContextForCompanionObjectAccessorIfRequiredOrNull( @NotNull ClassDescriptor companionObjectDescriptor, @NotNull CodegenContext contextBeforeInline ) { @@ -2870,6 +2870,10 @@ public class ExpressionCodegen extends KtVisitor impleme return null; } + if (!state.getLanguageVersionSettings().supportsFeature(LanguageFeature.ProperVisibilityForCompanionObjectInstanceField)) { + return null; + } + int accessFlag = AsmUtil.getVisibilityAccessFlag(companionObjectDescriptor); CodegenContext context = contextBeforeInline.getFirstCrossInlineOrNonInlineContext(); diff --git a/compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_after.kt b/compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_after.kt new file mode 100644 index 00000000000..30e598bcc60 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_after.kt @@ -0,0 +1,13 @@ +// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField +// IGNORE_BACKEND: JVM_IR +// ^ TODO implement ProperVisibilityForCompanionObjectInstanceField feature support in JMV_IR + +class Host { + private companion object { + fun foo() = 1 + } + + fun test() = { foo() } +} + +// 1 synthetic access\$ \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_before.kt b/compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_before.kt new file mode 100644 index 00000000000..0c67b618a57 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_before.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: -ProperVisibilityForCompanionObjectInstanceField + +class Host { + private companion object { + fun foo() = 1 + } + + fun test() = { foo() } +} + +// 0 synthetic access\$ \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 7296a520c42..833294c950a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -920,6 +920,16 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { public void testKt14258_5() throws Exception { runTest("compiler/testData/codegen/bytecodeText/companion/kt14258_5.kt"); } + + @TestMetadata("privateCompanionObjectAccessors_after.kt") + public void testPrivateCompanionObjectAccessors_after() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_after.kt"); + } + + @TestMetadata("privateCompanionObjectAccessors_before.kt") + public void testPrivateCompanionObjectAccessors_before() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_before.kt"); + } } @TestMetadata("compiler/testData/codegen/bytecodeText/conditions") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index b6bf34f258e..814e8e82cd0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -920,6 +920,16 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { public void testKt14258_5() throws Exception { runTest("compiler/testData/codegen/bytecodeText/companion/kt14258_5.kt"); } + + @TestMetadata("privateCompanionObjectAccessors_after.kt") + public void testPrivateCompanionObjectAccessors_after() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_after.kt"); + } + + @TestMetadata("privateCompanionObjectAccessors_before.kt") + public void testPrivateCompanionObjectAccessors_before() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_before.kt"); + } } @TestMetadata("compiler/testData/codegen/bytecodeText/conditions")