From b6dc99b98e8847af1dd739c1ea5240d044e05d43 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Thu, 15 Oct 2020 10:10:47 +0200 Subject: [PATCH] Skip java defaults in EXPLICIT_OVERRIDE_REQUIRED_IN_MIXED_MODE check #KT-42674 Fixed --- .../ir/FirBlackBoxCodegenTestGenerated.java | 20 ++++++++++++++ .../resolve/jvm/checkers/JvmDefaultChecker.kt | 7 ++++- .../jvm8/defaults/allCompatibility/kt42674.kt | 26 ++++++++++++++++++ .../jvm8/defaults/compatibility/kt42674.kt | 27 +++++++++++++++++++ .../codegen/box/jvm8/defaults/kt42674.kt | 27 +++++++++++++++++++ .../jvm8/defaults/noDefaultImpls/kt42674.kt | 26 ++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 20 ++++++++++++++ .../LightAnalysisModeTestGenerated.java | 20 ++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 20 ++++++++++++++ 9 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/jvm8/defaults/allCompatibility/kt42674.kt create mode 100644 compiler/testData/codegen/box/jvm8/defaults/compatibility/kt42674.kt create mode 100644 compiler/testData/codegen/box/jvm8/defaults/kt42674.kt create mode 100644 compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt42674.kt 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 86df109ae8f..a2353f97afa 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 @@ -16302,6 +16302,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvm8/defaults/kt40920.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/kt42674.kt"); + } + @TestMetadata("oneImplementation.kt") public void testOneImplementation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/oneImplementation.kt"); @@ -16464,6 +16469,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/kt14243_2.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/kt42674.kt"); + } + @TestMetadata("privateFunInInterface.kt") public void testPrivateFunInInterface() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/privateFunInInterface.kt"); @@ -16575,6 +16585,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvm8/defaults/compatibility/interfaceExtension.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/compatibility/kt42674.kt"); + } + @TestMetadata("propertyAnnotation.kt") public void testPropertyAnnotation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/compatibility/propertyAnnotation.kt"); @@ -16736,6 +16751,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt40920.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt42674.kt"); + } + @TestMetadata("privateFunInInterface.kt") public void testPrivateFunInInterface() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/privateFunInInterface.kt"); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmDefaultChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmDefaultChecker.kt index c9a90939f23..474864bfd49 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmDefaultChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmDefaultChecker.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.config.JvmAnalysisFlags import org.jetbrains.kotlin.config.JvmDefaultMode import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor import org.jetbrains.kotlin.load.kotlin.computeJvmDescriptor import org.jetbrains.kotlin.psi.KtDeclaration @@ -200,7 +201,11 @@ class JvmDefaultChecker(val jvmTarget: JvmTarget, project: Project) : Declaratio val classMembers = inheritedFun.overriddenDescriptors.filter { !isInterface(it.containingDeclaration) && !isAnnotationClass(it.containingDeclaration) } val implicitDefaultImplsDelegate = - classMembers.firstOrNull { getNonPrivateTraitMembersForDelegation(it, true)?.isCompiledToJvmDefaultWithProperMode(jvmDefaultMode) == false } + classMembers.firstOrNull { + //TODO: additional processing for platform dependent method is required (https://youtrack.jetbrains.com/issue/KT-42697) + it !is JavaCallableMemberDescriptor && + getNonPrivateTraitMembersForDelegation(it, true)?.isCompiledToJvmDefaultWithProperMode(jvmDefaultMode) == false + } if (implicitDefaultImplsDelegate != null) return implicitDefaultImplsDelegate return classMembers.firstNotNullResult { findPossibleClashMember(it, jvmDefaultMode) } } diff --git a/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/kt42674.kt b/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/kt42674.kt new file mode 100644 index 00000000000..9e184a88a78 --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/kt42674.kt @@ -0,0 +1,26 @@ +// !JVM_DEFAULT_MODE: all-compatibility +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_RUNTIME +// FILE: A.java + +public interface A { + default String foo() { + return "fail"; + } +} +// FILE: B.java + +public abstract class B implements A {} + +// FILE: test.kt + +interface KDefault : A { + override fun foo() = "OK" +} + +class Problem : B(), KDefault + +fun box(): String { + return Problem().foo() +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/jvm8/defaults/compatibility/kt42674.kt b/compiler/testData/codegen/box/jvm8/defaults/compatibility/kt42674.kt new file mode 100644 index 00000000000..4edb7d125f6 --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/compatibility/kt42674.kt @@ -0,0 +1,27 @@ +// !JVM_DEFAULT_MODE: compatibility +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_RUNTIME +// FILE: A.java + +public interface A { + default String foo() { + return "fail"; + } +} +// FILE: B.java + +public abstract class B implements A {} + +// FILE: test.kt + +interface KDefault : A { + @JvmDefault + override fun foo() = "OK" +} + +class Problem : B(), KDefault + +fun box(): String { + return Problem().foo() +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/jvm8/defaults/kt42674.kt b/compiler/testData/codegen/box/jvm8/defaults/kt42674.kt new file mode 100644 index 00000000000..986599605f9 --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/kt42674.kt @@ -0,0 +1,27 @@ +// !JVM_DEFAULT_MODE: enable +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_RUNTIME +// FILE: A.java + +public interface A { + default String foo() { + return "fail"; + } +} +// FILE: B.java + +public abstract class B implements A {} + +// FILE: test.kt + +interface KDefault : A { + @JvmDefault + override fun foo() = "OK" +} + +class Problem : B(), KDefault + +fun box(): String { + return Problem().foo() +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt42674.kt b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt42674.kt new file mode 100644 index 00000000000..ca728d3b2d5 --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt42674.kt @@ -0,0 +1,26 @@ +// !JVM_DEFAULT_MODE: all +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_RUNTIME +// FILE: A.java + +public interface A { + default String foo() { + return "fail"; + } +} +// FILE: B.java + +public abstract class B implements A {} + +// FILE: test.kt + +interface KDefault : A { + override fun foo() = "OK" +} + +class Problem : B(), KDefault + +fun box(): String { + return Problem().foo() +} \ 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 e369dea175d..4d3a011370e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -17697,6 +17697,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvm8/defaults/kt40920.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/kt42674.kt"); + } + @TestMetadata("oneImplementation.kt") public void testOneImplementation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/oneImplementation.kt"); @@ -17859,6 +17864,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/kt14243_2.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/kt42674.kt"); + } + @TestMetadata("privateFunInInterface.kt") public void testPrivateFunInInterface() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/privateFunInInterface.kt"); @@ -17970,6 +17980,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvm8/defaults/compatibility/interfaceExtension.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/compatibility/kt42674.kt"); + } + @TestMetadata("propertyAnnotation.kt") public void testPropertyAnnotation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/compatibility/propertyAnnotation.kt"); @@ -18131,6 +18146,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt40920.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt42674.kt"); + } + @TestMetadata("privateFunInInterface.kt") public void testPrivateFunInInterface() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/privateFunInInterface.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index a1541f95c47..4082539fb39 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -17697,6 +17697,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvm8/defaults/kt40920.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/kt42674.kt"); + } + @TestMetadata("oneImplementation.kt") public void testOneImplementation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/oneImplementation.kt"); @@ -17859,6 +17864,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/kt14243_2.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/kt42674.kt"); + } + @TestMetadata("privateFunInInterface.kt") public void testPrivateFunInInterface() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/privateFunInInterface.kt"); @@ -17970,6 +17980,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvm8/defaults/compatibility/interfaceExtension.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/compatibility/kt42674.kt"); + } + @TestMetadata("propertyAnnotation.kt") public void testPropertyAnnotation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/compatibility/propertyAnnotation.kt"); @@ -18131,6 +18146,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt40920.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt42674.kt"); + } + @TestMetadata("privateFunInInterface.kt") public void testPrivateFunInInterface() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/privateFunInInterface.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 769d37db42d..2c7da2271c6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -16302,6 +16302,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvm8/defaults/kt40920.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/kt42674.kt"); + } + @TestMetadata("oneImplementation.kt") public void testOneImplementation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/oneImplementation.kt"); @@ -16464,6 +16469,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/kt14243_2.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/kt42674.kt"); + } + @TestMetadata("privateFunInInterface.kt") public void testPrivateFunInInterface() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/privateFunInInterface.kt"); @@ -16575,6 +16585,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvm8/defaults/compatibility/interfaceExtension.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/compatibility/kt42674.kt"); + } + @TestMetadata("propertyAnnotation.kt") public void testPropertyAnnotation() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/compatibility/propertyAnnotation.kt"); @@ -16736,6 +16751,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt40920.kt"); } + @TestMetadata("kt42674.kt") + public void testKt42674() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt42674.kt"); + } + @TestMetadata("privateFunInInterface.kt") public void testPrivateFunInInterface() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/privateFunInInterface.kt");