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 ac8b78f5a47..1d23046739a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/context/CodegenContext.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/context/CodegenContext.java @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.codegen.*; import org.jetbrains.kotlin.codegen.binding.MutableClosure; import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper; +import org.jetbrains.kotlin.config.JvmDefaultMode; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.load.java.JavaVisibilities; import org.jetbrains.kotlin.load.java.sam.SamConstructorDescriptor; @@ -651,7 +652,10 @@ public abstract class CodegenContext { return descriptor; } - if (JvmAnnotationUtilKt.isCompiledToJvmDefaultIfNoAbstract(descriptor, getState().getJvmDefaultMode()) && descriptorContext instanceof DefaultImplsClassContext) { + //in other default modes there shouldn't be any accessors form DefaultImpls to Interface cause all compiled inside interface + if (getState().getJvmDefaultMode() == JvmDefaultMode.ENABLE && + JvmAnnotationUtilKt.hasJvmDefaultAnnotation(descriptor) && + descriptorContext instanceof DefaultImplsClassContext) { descriptorContext = ((DefaultImplsClassContext) descriptorContext).getInterfaceContext(); } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.kt index dd0e2dd85ff..ee796566f79 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.kt @@ -456,7 +456,9 @@ class KotlinTypeMapper @JvmOverloads constructor( if (isInterface && (superCall || descriptor.visibility == Visibilities.PRIVATE || isAccessor(descriptor))) { thisClass = mapClass(functionParent) dispatchReceiverKotlinType = functionParent.defaultType - if (declarationOwner is JavaClassDescriptor || declarationFunctionDescriptor.isCompiledToJvmDefaultIfNoAbstract(jvmDefaultMode)) { + if (declarationOwner is JavaClassDescriptor || + (declarationFunctionDescriptor.isCompiledToJvmDefaultIfNoAbstract(jvmDefaultMode) && !isAccessor(descriptor)) + ) { invokeOpcode = INVOKESPECIAL signature = mapSignatureSkipGeneric(functionDescriptor) returnKotlinType = functionDescriptor.returnType diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index e1ffb514a33..37a254f0f48 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -14909,6 +14909,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: "); } + @TestMetadata("accessor.kt") + public void testAccessor() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessor.kt"); + } + + @TestMetadata("accessorFromCompanion.kt") + public void testAccessorFromCompanion() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessorFromCompanion.kt"); + } + public void testAllFilesPresentInAllCompatibility() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvm8/defaults/allCompatibility"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } @@ -14973,6 +14983,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/interfaceExtension.kt"); } + @TestMetadata("privateFunInInterface.kt") + public void testPrivateFunInInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/privateFunInInterface.kt"); + } + @TestMetadata("propertyAnnotation.kt") public void testPropertyAnnotation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/propertyAnnotation.kt"); @@ -15093,6 +15108,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: "); } + @TestMetadata("accessor.kt") + public void testAccessor() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessor.kt"); + } + + @TestMetadata("accessorFromCompanion.kt") + public void testAccessorFromCompanion() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessorFromCompanion.kt"); + } + public void testAllFilesPresentInNoDefaultImpls() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } @@ -15152,6 +15177,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/interfaceExtension.kt"); } + @TestMetadata("privateFunInInterface.kt") + public void testPrivateFunInInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/privateFunInInterface.kt"); + } + @TestMetadata("propertyAnnotation.kt") public void testPropertyAnnotation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/propertyAnnotation.kt"); diff --git a/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessor.kt b/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessor.kt new file mode 100644 index 00000000000..392b0ea62d9 --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessor.kt @@ -0,0 +1,34 @@ +// !JVM_DEFAULT_MODE: all-compatibility +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_RUNTIME + +var storage = "fail" + +interface Test { + + private var foo: String + get() = storage + set(value) { + storage = value + } + + private fun bar(): String { + return "K" + } + + fun call(): String { + return { + foo = "O" + foo + bar() + } () + } +} + +class TestClass : Test { + +} + +fun box(): String { + return TestClass().call() +} diff --git a/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessorFromCompanion.kt b/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessorFromCompanion.kt new file mode 100644 index 00000000000..18800902361 --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessorFromCompanion.kt @@ -0,0 +1,25 @@ +// !JVM_DEFAULT_MODE: all-compatibility +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_RUNTIME + +interface Test { + private val foo: String + get() = "O" + + private fun bar(): String { + return "K" + } + + companion object { + fun call(test: Test): String { + return test.foo + test.bar() + } + } +} + +class TestClass : Test + +fun box(): String { + return Test.call(TestClass()) +} diff --git a/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/privateFunInInterface.kt b/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/privateFunInInterface.kt new file mode 100644 index 00000000000..8cc71a9869b --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/privateFunInInterface.kt @@ -0,0 +1,24 @@ +// !JVM_DEFAULT_MODE: all-compatibility +// IGNORE_BACKEND_FIR: JVM_IR +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_RUNTIME + +interface Test { + fun test(): String { + return privateFun() + privateProp + } + + private fun privateFun(): String { + return "O" + } + + private val privateProp: String + get() = "K" +} + +class TestImpl: Test + +fun box(): String { + return TestImpl().test() +} diff --git a/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessor.kt b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessor.kt new file mode 100644 index 00000000000..a63670bddd6 --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessor.kt @@ -0,0 +1,34 @@ +// !JVM_DEFAULT_MODE: all +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_RUNTIME + +var storage = "fail" + +interface Test { + + private var foo: String + get() = storage + set(value) { + storage = value + } + + private fun bar(): String { + return "K" + } + + fun call(): String { + return { + foo = "O" + foo + bar() + } () + } +} + +class TestClass : Test { + +} + +fun box(): String { + return TestClass().call() +} diff --git a/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessorFromCompanion.kt b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessorFromCompanion.kt new file mode 100644 index 00000000000..0641bcc8799 --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessorFromCompanion.kt @@ -0,0 +1,25 @@ +// !JVM_DEFAULT_MODE: all +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_RUNTIME + +interface Test { + private val foo: String + get() = "O" + + private fun bar(): String { + return "K" + } + + companion object { + fun call(test: Test): String { + return test.foo + test.bar() + } + } +} + +class TestClass : Test + +fun box(): String { + return Test.call(TestClass()) +} diff --git a/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/privateFunInInterface.kt b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/privateFunInInterface.kt new file mode 100644 index 00000000000..8db2397e6f1 --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/privateFunInInterface.kt @@ -0,0 +1,24 @@ +// !JVM_DEFAULT_MODE: all +// IGNORE_BACKEND_FIR: JVM_IR +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_RUNTIME + +interface Test { + fun test(): String { + return privateFun() + privateProp + } + + private fun privateFun(): String { + return "O" + } + + private val privateProp: String + get() = "K" +} + +class TestImpl: Test + +fun box(): String { + return TestImpl().test() +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index e9f041a54e4..6908e83af87 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -16124,6 +16124,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } + @TestMetadata("accessor.kt") + public void testAccessor() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessor.kt"); + } + + @TestMetadata("accessorFromCompanion.kt") + public void testAccessorFromCompanion() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessorFromCompanion.kt"); + } + public void testAllFilesPresentInAllCompatibility() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvm8/defaults/allCompatibility"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } @@ -16188,6 +16198,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/interfaceExtension.kt"); } + @TestMetadata("privateFunInInterface.kt") + public void testPrivateFunInInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/privateFunInInterface.kt"); + } + @TestMetadata("propertyAnnotation.kt") public void testPropertyAnnotation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/propertyAnnotation.kt"); @@ -16308,6 +16323,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } + @TestMetadata("accessor.kt") + public void testAccessor() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessor.kt"); + } + + @TestMetadata("accessorFromCompanion.kt") + public void testAccessorFromCompanion() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessorFromCompanion.kt"); + } + public void testAllFilesPresentInNoDefaultImpls() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } @@ -16367,6 +16392,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/interfaceExtension.kt"); } + @TestMetadata("privateFunInInterface.kt") + public void testPrivateFunInInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/privateFunInInterface.kt"); + } + @TestMetadata("propertyAnnotation.kt") public void testPropertyAnnotation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/propertyAnnotation.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 5ff29a02ba8..b1e3b637079 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -16124,6 +16124,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } + @TestMetadata("accessor.kt") + public void testAccessor() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessor.kt"); + } + + @TestMetadata("accessorFromCompanion.kt") + public void testAccessorFromCompanion() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessorFromCompanion.kt"); + } + public void testAllFilesPresentInAllCompatibility() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvm8/defaults/allCompatibility"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } @@ -16188,6 +16198,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/interfaceExtension.kt"); } + @TestMetadata("privateFunInInterface.kt") + public void testPrivateFunInInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/privateFunInInterface.kt"); + } + @TestMetadata("propertyAnnotation.kt") public void testPropertyAnnotation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/propertyAnnotation.kt"); @@ -16308,6 +16323,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } + @TestMetadata("accessor.kt") + public void testAccessor() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessor.kt"); + } + + @TestMetadata("accessorFromCompanion.kt") + public void testAccessorFromCompanion() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessorFromCompanion.kt"); + } + public void testAllFilesPresentInNoDefaultImpls() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } @@ -16367,6 +16392,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/interfaceExtension.kt"); } + @TestMetadata("privateFunInInterface.kt") + public void testPrivateFunInInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/privateFunInInterface.kt"); + } + @TestMetadata("propertyAnnotation.kt") public void testPropertyAnnotation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/propertyAnnotation.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index b0952baccf7..bf61f122229 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -14909,6 +14909,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); } + @TestMetadata("accessor.kt") + public void testAccessor() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessor.kt"); + } + + @TestMetadata("accessorFromCompanion.kt") + public void testAccessorFromCompanion() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/accessorFromCompanion.kt"); + } + public void testAllFilesPresentInAllCompatibility() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvm8/defaults/allCompatibility"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } @@ -14973,6 +14983,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/interfaceExtension.kt"); } + @TestMetadata("privateFunInInterface.kt") + public void testPrivateFunInInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/privateFunInInterface.kt"); + } + @TestMetadata("propertyAnnotation.kt") public void testPropertyAnnotation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/propertyAnnotation.kt"); @@ -15093,6 +15108,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); } + @TestMetadata("accessor.kt") + public void testAccessor() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessor.kt"); + } + + @TestMetadata("accessorFromCompanion.kt") + public void testAccessorFromCompanion() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/accessorFromCompanion.kt"); + } + public void testAllFilesPresentInNoDefaultImpls() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } @@ -15152,6 +15177,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/interfaceExtension.kt"); } + @TestMetadata("privateFunInInterface.kt") + public void testPrivateFunInInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/privateFunInInterface.kt"); + } + @TestMetadata("propertyAnnotation.kt") public void testPropertyAnnotation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/propertyAnnotation.kt");