From dc2485ae71e77d9ff16cc8484197443a74b41aa5 Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Mon, 26 Apr 2021 16:16:25 +0200 Subject: [PATCH] Support suspend functions as superinterfaces Forbid mixing suspend and non-suspend functional supertypes. Since JVM BE generates suspend functional types as non-suspend ones with SuspendFunction marker interface, there is not way to distinguish non-suspend functional type from suspend one if they are mixed. #KT-18707 Fixed --- ...irOldFrontendDiagnosticsTestGenerated.java | 130 ++++++++++++++++++ ...DiagnosticsWithLightTreeTestGenerated.java | 130 ++++++++++++++++++ .../FirBlackBoxCodegenTestGenerated.java | 6 + .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../rendering/DefaultErrorMessages.java | 1 + .../kotlin/resolve/BodyResolver.java | 7 +- .../resolve/PlatformConfiguratorBase.kt | 1 + .../SuspendFunctionAsSupertypeChecker.kt | 40 ++++++ .../coroutines/suspendFunctionAsSupertype.kt | 31 +++++ ...ixingSuspendAndNonSuspendSupertypes.fir.kt | 18 +++ .../mixingSuspendAndNonSuspendSupertypes.kt | 18 +++ ...dNonSuspendSupertypesThruSuperClass.fir.kt | 29 ++++ ...ndAndNonSuspendSupertypesThruSuperClass.kt | 29 ++++ ...pendSupertypesThruSuperFunInterface.fir.kt | 20 +++ ...nSuspendSupertypesThruSuperFunInterface.kt | 20 +++ ...SuspendSupertypesThruSuperinterface.fir.kt | 48 +++++++ ...dNonSuspendSupertypesThruSuperinterface.kt | 48 +++++++ .../kSuspendFunctionN/simple.kt | 20 +++ ...ixingSuspendAndNonSuspendSupertypes.fir.kt | 19 +++ .../mixingSuspendAndNonSuspendSupertypes.kt | 19 +++ ...dNonSuspendSupertypesThruSuperClass.fir.kt | 27 ++++ ...ndAndNonSuspendSupertypesThruSuperClass.kt | 27 ++++ ...pendSupertypesThruSuperFunInterface.fir.kt | 55 ++++++++ ...nSuspendSupertypesThruSuperFunInterface.kt | 55 ++++++++ ...SuspendSupertypesThruSuperinterface.fir.kt | 55 ++++++++ ...dNonSuspendSupertypesThruSuperinterface.kt | 55 ++++++++ .../simple/simple.kt | 20 +++ ...ixingSuspendAndNonSuspendSupertypes.fir.kt | 20 +++ .../mixingSuspendAndNonSuspendSupertypes.kt | 20 +++ ...dNonSuspendSupertypesThruSuperClass.fir.kt | 29 ++++ ...ndAndNonSuspendSupertypesThruSuperClass.kt | 29 ++++ ...pendSupertypesThruSuperFunInterface.fir.kt | 57 ++++++++ ...nSuspendSupertypesThruSuperFunInterface.kt | 57 ++++++++ ...SuspendSupertypesThruSuperinterface.fir.kt | 57 ++++++++ ...dNonSuspendSupertypesThruSuperinterface.kt | 57 ++++++++ .../suspendFunctionN/simple.kt | 22 +++ .../test/runners/DiagnosticTestGenerated.java | 130 ++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 + .../IrBlackBoxCodegenTestGenerated.java | 6 + .../LightAnalysisModeTestGenerated.java | 5 + .../kotlin/config/LanguageVersionSettings.kt | 2 + .../IrJsCodegenBoxES6TestGenerated.java | 5 + .../IrJsCodegenBoxTestGenerated.java | 5 + .../semantics/JsCodegenBoxTestGenerated.java | 5 + 44 files changed, 1439 insertions(+), 2 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/SuspendFunctionAsSupertypeChecker.kt create mode 100644 compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/simple.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/simple.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.fir.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt create mode 100644 compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/simple.kt diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 03056df6aab..9f49c2d7e06 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -5680,6 +5680,136 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/coroutines/callableReference/outsideSuspend.kt"); } } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype") + @TestDataPath("$PROJECT_ROOT") + public class SuspendFunctionAsSupertype { + @Test + public void testAllFilesPresentInSuspendFunctionAsSupertype() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN") + @TestDataPath("$PROJECT_ROOT") + public class KSuspendFunctionN { + @Test + public void testAllFilesPresentInKSuspendFunctionN() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypes.kt") + public void testMixingSuspendAndNonSuspendSupertypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperFunInterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperinterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/simple.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple") + @TestDataPath("$PROJECT_ROOT") + public class Simple { + @Test + public void testAllFilesPresentInSimple() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypes.kt") + public void testMixingSuspendAndNonSuspendSupertypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperFunInterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperinterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/simple.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN") + @TestDataPath("$PROJECT_ROOT") + public class SuspendFunctionN { + @Test + public void testAllFilesPresentInSuspendFunctionN() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypes.kt") + public void testMixingSuspendAndNonSuspendSupertypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperFunInterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperinterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/simple.kt"); + } + } + } } @Nested diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 4feb5ca30e3..84dbdd9b91b 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -5680,6 +5680,136 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/coroutines/callableReference/outsideSuspend.kt"); } } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype") + @TestDataPath("$PROJECT_ROOT") + public class SuspendFunctionAsSupertype { + @Test + public void testAllFilesPresentInSuspendFunctionAsSupertype() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN") + @TestDataPath("$PROJECT_ROOT") + public class KSuspendFunctionN { + @Test + public void testAllFilesPresentInKSuspendFunctionN() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypes.kt") + public void testMixingSuspendAndNonSuspendSupertypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperFunInterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperinterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/simple.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple") + @TestDataPath("$PROJECT_ROOT") + public class Simple { + @Test + public void testAllFilesPresentInSimple() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypes.kt") + public void testMixingSuspendAndNonSuspendSupertypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperFunInterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperinterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/simple.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN") + @TestDataPath("$PROJECT_ROOT") + public class SuspendFunctionN { + @Test + public void testAllFilesPresentInSuspendFunctionN() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypes.kt") + public void testMixingSuspendAndNonSuspendSupertypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperFunInterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperinterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/simple.kt"); + } + } + } } @Nested diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 2ff32e7fc7a..9d55cf9411b 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -9366,6 +9366,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/coroutines/suspendFunImportedFromObject.kt"); } + @Test + @TestMetadata("suspendFunctionAsSupertype.kt") + public void testSuspendFunctionAsSupertype() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt"); + } + @Test @TestMetadata("suspendFunctionMethodReference.kt") public void testSuspendFunctionMethodReference() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 6bad1c467f3..12c8be7b7f2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -325,6 +325,7 @@ public interface Errors { DiagnosticFactory0 SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 SUPERTYPE_IS_KSUSPEND_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 MIXING_SUSPEND_AND_NON_SUSPEND_SUPERTYPES = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 MANY_CLASSES_IN_SUPERTYPE_LIST = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 SUPERTYPE_APPEARS_TWICE = DiagnosticFactory0.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 06e6a9bdc7a..9efbf3c8417 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -635,6 +635,7 @@ public class DefaultErrorMessages { MAP.put(SUPERTYPE_INITIALIZED_IN_INTERFACE, "Interfaces cannot initialize supertypes"); MAP.put(SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE, "Suspend function type is not allowed as supertypes"); MAP.put(SUPERTYPE_IS_KSUSPEND_FUNCTION_TYPE, "KSuspendFunctionN interfaces are not allowed as supertypes"); + MAP.put(MIXING_SUSPEND_AND_NON_SUSPEND_SUPERTYPES, "Mixing suspend and non-suspend supertypes is not allowed"); MAP.put(CLASS_IN_SUPERTYPE_FOR_ENUM, "Enum class cannot inherit from classes"); MAP.put(CONSTRUCTOR_IN_INTERFACE, "An interface may not have a constructor"); MAP.put(METHOD_OF_ANY_IMPLEMENTED_IN_INTERFACE, "An interface may not implement a method of 'Any'"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java index c546761cf83..67aeb07708c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java @@ -587,10 +587,13 @@ public class BodyResolver { if (FunctionTypesKt.isExtensionFunctionType(supertype)) { trace.report(SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE.on(typeReference)); } - else if (FunctionTypesKt.isSuspendFunctionType(supertype)) { + else if (FunctionTypesKt.isSuspendFunctionType(supertype) && + !languageVersionSettings.supportsFeature(LanguageFeature.SuspendFunctionAsSupertype) + ) { trace.report(SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE.on(typeReference)); } - else if (FunctionTypesKt.isKSuspendFunctionType(supertype)) { + else if (FunctionTypesKt.isKSuspendFunctionType(supertype) && + !languageVersionSettings.supportsFeature(LanguageFeature.SuspendFunctionAsSupertype)) { trace.report(SUPERTYPE_IS_KSUSPEND_FUNCTION_TYPE.on(typeReference)); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt index c7870622209..b2a9b418640 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt @@ -44,6 +44,7 @@ private val DEFAULT_DECLARATION_CHECKERS = listOf( SealedInheritorInSamePackageChecker, SealedInheritorInSameModuleChecker, SealedInterfaceAllowedChecker, + SuspendFunctionAsSupertypeChecker, ) private val DEFAULT_CALL_CHECKERS = listOf( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/SuspendFunctionAsSupertypeChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/SuspendFunctionAsSupertypeChecker.kt new file mode 100644 index 00000000000..a260049ebd0 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/SuspendFunctionAsSupertypeChecker.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ +package org.jetbrains.kotlin.resolve.checkers + +import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor +import org.jetbrains.kotlin.builtins.functions.FunctionClassKind +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.psi.KtClassOrObject +import org.jetbrains.kotlin.psi.KtDeclaration +import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperClassifiers + +object SuspendFunctionAsSupertypeChecker : DeclarationChecker { + override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) { + if (!context.languageVersionSettings.supportsFeature(LanguageFeature.SuspendFunctionAsSupertype)) return + if (descriptor !is ClassDescriptor) return + + val functionalSupertypes = descriptor.getAllSuperClassifiers().filterIsInstance().toList() + + if (functionalSupertypes.none { + it.functionKind == FunctionClassKind.SuspendFunction || + it.functionKind == FunctionClassKind.KSuspendFunction + } + ) return + + if (functionalSupertypes.any { + it.functionKind == FunctionClassKind.Function || + it.functionKind == FunctionClassKind.KFunction + } + ) { + val reportOn = (declaration as? KtClassOrObject)?.getSuperTypeList() ?: declaration + context.trace.report(Errors.MIXING_SUSPEND_AND_NON_SUSPEND_SUPERTYPES.on(reportOn)) + } + } +} + diff --git a/compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt b/compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt new file mode 100644 index 00000000000..18d88a54ae5 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt @@ -0,0 +1,31 @@ +// WITH_RUNTIME +// IGNORE_BACKEND: JS, JS_IR, JVM +// !LANGUAGE: +SuspendFunctionAsSupertype + +import kotlin.coroutines.* + +var res = "FAIL" + +class C: suspend () -> Unit { + override suspend fun invoke() { + res = "OK" + } +} + +fun box(): String { + val o: suspend () -> Unit = object : suspend () -> Unit { + override suspend fun invoke() { + res = "OK" + } + } + o.startCoroutine(Continuation(EmptyCoroutineContext) { + it.getOrThrow() + }) + if (res != "OK") return "FAIL 1: $res" + + res = "FAIL 2" + C().startCoroutine(Continuation(EmptyCoroutineContext) { + it.getOrThrow() + }) + return res +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypes.fir.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypes.fir.kt new file mode 100644 index 00000000000..4ba387ac1c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypes.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED + +import kotlin.reflect.* + +class C: KSuspendFunction0, () -> Unit { + override suspend fun invoke() { + } +} + +interface I: KSuspendFunction0, () -> Unit { +} + +object O: KSuspendFunction0, () -> Unit { + override suspend fun invoke() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt new file mode 100644 index 00000000000..a8e304860bf --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED + +import kotlin.reflect.* + +class C: KSuspendFunction0, () -> Unit { + override suspend fun invoke() { + } +} + +interface I: KSuspendFunction0, () -> Unit { +} + +object O: KSuspendFunction0, () -> Unit { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.fir.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.fir.kt new file mode 100644 index 00000000000..1a44e0821b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.fir.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED + +import kotlin.reflect.* + +abstract class CSuper: () -> Unit + +class C: CSuper(), KSuspendFunction0 { + override suspend fun invoke() { + } +} + +object O: CSuper(), KSuspendFunction0 { + override suspend fun invoke() { + } +} + +abstract class SCSuper: KSuspendFunction0 + +class C1: SCSuper(), () -> Unit { + override suspend fun invoke() { + } +} + +object O1: SCSuper(), () -> Unit { + override suspend fun invoke() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt new file mode 100644 index 00000000000..699573e7413 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED + +import kotlin.reflect.* + +abstract class CSuper: () -> Unit + +class C: CSuper(), KSuspendFunction0 { + override suspend fun invoke() { + } +} + +object O: CSuper(), KSuspendFunction0 { + override suspend fun invoke() { + } +} + +abstract class SCSuper: KSuspendFunction0 + +class C1: SCSuper(), () -> Unit { + override suspend fun invoke() { + } +} + +object O1: SCSuper(), () -> Unit { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.fir.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.fir.kt new file mode 100644 index 00000000000..02735fe5e92 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED + +import kotlin.reflect.* + +fun interface FISuper: () -> Unit + +class C: KSuspendFunction0, FISuper { + override suspend fun invoke() { + } +} + +interface I: KSuspendFunction0, FISuper { +} + +object O: KSuspendFunction0, FISuper { + override suspend fun invoke() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt new file mode 100644 index 00000000000..f780e12b114 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED + +import kotlin.reflect.* + +fun interface FISuper: () -> Unit + +class C: KSuspendFunction0, FISuper { + override suspend fun invoke() { + } +} + +interface I: KSuspendFunction0, FISuper { +} + +object O: KSuspendFunction0, FISuper { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.fir.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.fir.kt new file mode 100644 index 00000000000..4b04fe2c5d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.fir.kt @@ -0,0 +1,48 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED + +import kotlin.reflect.* + +interface ISuper: () -> Unit + +class C: KSuspendFunction0, ISuper { + override suspend fun invoke() { + } +} + +interface I: KSuspendFunction0, ISuper { +} + +object O: KSuspendFunction0, ISuper { + override suspend fun invoke() { + } +} + +interface SISuper: KSuspendFunction0 + +class C1: SISuper, () -> Unit { + override suspend fun invoke() { + } +} + +interface I1: SISuper, () -> Unit { +} + +object O1: SISuper, () -> Unit { + override suspend fun invoke() { + } +} + +class C2: SISuper, ISuper { + override suspend fun invoke() { + } +} + +interface I2: SISuper, ISuper { +} + +object O2: SISuper, ISuper { + override suspend fun invoke() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt new file mode 100644 index 00000000000..9bd3a1d012d --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt @@ -0,0 +1,48 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED + +import kotlin.reflect.* + +interface ISuper: () -> Unit + +class C: KSuspendFunction0, ISuper { + override suspend fun invoke() { + } +} + +interface I: KSuspendFunction0, ISuper { +} + +object O: KSuspendFunction0, ISuper { + override suspend fun invoke() { + } +} + +interface SISuper: KSuspendFunction0 + +class C1: SISuper, () -> Unit { + override suspend fun invoke() { + } +} + +interface I1: SISuper, () -> Unit { +} + +object O1: SISuper, () -> Unit { + override suspend fun invoke() { + } +} + +class C2: SISuper, ISuper { + override suspend fun invoke() { + } +} + +interface I2: SISuper, ISuper { +} + +object O2: SISuper, ISuper { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/simple.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/simple.kt new file mode 100644 index 00000000000..eaa7bae4095 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/simple.kt @@ -0,0 +1,20 @@ +// FIR_IDENTICAL +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// FIR_IDENTICAL +// DIAGNOSTICS: -ABSTRACT_MEMBER_NOT_IMPLEMENTED + +import kotlin.reflect.* + +class C: KSuspendFunction0 { + override suspend fun invoke() { + } +} + +interface I: KSuspendFunction0 { +} + +object O: KSuspendFunction0 { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.fir.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.fir.kt new file mode 100644 index 00000000000..2e2ee9204f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.fir.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +class C: suspend () -> Unit, () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI: suspend () -> Unit, () -> Unit { +} + +interface I: suspend () -> Unit, () -> Unit { +} + +object O: suspend () -> Unit, () -> Unit { + override suspend fun invoke() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.kt new file mode 100644 index 00000000000..19297601685 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +class C: suspend () -> Unit, () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI: suspend () -> Unit, () -> Unit { +} + +interface I: suspend () -> Unit, () -> Unit { +} + +object O: suspend () -> Unit, () -> Unit { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.fir.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.fir.kt new file mode 100644 index 00000000000..e15c72476c6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.fir.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +abstract class CSuper: () -> Unit + +class C: CSuper(), suspend () -> Unit { + override suspend fun invoke() { + } +} + +object O: CSuper(), suspend () -> Unit { + override suspend fun invoke() { + } +} + +abstract class SCSuper: suspend () -> Unit + +class C1: SCSuper(), () -> Unit { + override suspend fun invoke() { + } +} + +object O1: SCSuper(), () -> Unit { + override suspend fun invoke() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt new file mode 100644 index 00000000000..551de20be71 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt @@ -0,0 +1,27 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +abstract class CSuper: () -> Unit + +class C: CSuper(), suspend () -> Unit { + override suspend fun invoke() { + } +} + +object O: CSuper(), suspend () -> Unit { + override suspend fun invoke() { + } +} + +abstract class SCSuper: suspend () -> Unit + +class C1: SCSuper(), () -> Unit { + override suspend fun invoke() { + } +} + +object O1: SCSuper(), () -> Unit { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.fir.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.fir.kt new file mode 100644 index 00000000000..56378c72681 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.fir.kt @@ -0,0 +1,55 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +fun interface FISuper: () -> Unit + +class C: suspend () -> Unit, FISuper { + override suspend fun invoke() { + } +} + +fun interface FI: suspend () -> Unit, FISuper { +} + +interface I: suspend () -> Unit, FISuper { +} + +object O: suspend () -> Unit, FISuper { + override suspend fun invoke() { + } +} + +fun interface SFISuper: suspend () -> Unit + +class C1: SFISuper, () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI1: SFISuper, () -> Unit { +} + +interface I1: SFISuper, () -> Unit { +} + +object O1: SFISuper, () -> Unit { + override suspend fun invoke() { + } +} + +class C2: SFISuper, FISuper { + override suspend fun invoke() { + } +} + +fun interface FI2: SFISuper, FISuper { +} + +interface I2: SFISuper, FISuper { +} + +object O2: SFISuper, FISuper { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt new file mode 100644 index 00000000000..2166de80679 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt @@ -0,0 +1,55 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +fun interface FISuper: () -> Unit + +class C: suspend () -> Unit, FISuper { + override suspend fun invoke() { + } +} + +fun interface FI: suspend () -> Unit, FISuper { +} + +interface I: suspend () -> Unit, FISuper { +} + +object O: suspend () -> Unit, FISuper { + override suspend fun invoke() { + } +} + +fun interface SFISuper: suspend () -> Unit + +class C1: SFISuper, () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI1: SFISuper, () -> Unit { +} + +interface I1: SFISuper, () -> Unit { +} + +object O1: SFISuper, () -> Unit { + override suspend fun invoke() { + } +} + +class C2: SFISuper, FISuper { + override suspend fun invoke() { + } +} + +fun interface FI2: SFISuper, FISuper { +} + +interface I2: SFISuper, FISuper { +} + +object O2: SFISuper, FISuper { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.fir.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.fir.kt new file mode 100644 index 00000000000..ba3919175ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.fir.kt @@ -0,0 +1,55 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +interface ISuper: () -> Unit + +class C: suspend () -> Unit, ISuper { + override suspend fun invoke() { + } +} + +fun interface FI: suspend () -> Unit, ISuper { +} + +interface I: suspend () -> Unit, ISuper { +} + +object O: suspend () -> Unit, ISuper { + override suspend fun invoke() { + } +} + +interface SISuper: suspend () -> Unit + +class C1: SISuper, () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI1: SISuper, () -> Unit { +} + +interface I1: SISuper, () -> Unit { +} + +object O1: SISuper, () -> Unit { + override suspend fun invoke() { + } +} + +class C2: SISuper, ISuper { + override suspend fun invoke() { + } +} + +fun interface FI2: SISuper, ISuper { +} + +interface I2: SISuper, ISuper { +} + +object O2: SISuper, ISuper { + override suspend fun invoke() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt new file mode 100644 index 00000000000..09f6919ce92 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt @@ -0,0 +1,55 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +interface ISuper: () -> Unit + +class C: suspend () -> Unit, ISuper { + override suspend fun invoke() { + } +} + +fun interface FI: suspend () -> Unit, ISuper { +} + +interface I: suspend () -> Unit, ISuper { +} + +object O: suspend () -> Unit, ISuper { + override suspend fun invoke() { + } +} + +interface SISuper: suspend () -> Unit + +class C1: SISuper, () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI1: SISuper, () -> Unit { +} + +interface I1: SISuper, () -> Unit { +} + +object O1: SISuper, () -> Unit { + override suspend fun invoke() { + } +} + +class C2: SISuper, ISuper { + override suspend fun invoke() { + } +} + +fun interface FI2: SISuper, ISuper { +} + +interface I2: SISuper, ISuper { +} + +object O2: SISuper, ISuper { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/simple.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/simple.kt new file mode 100644 index 00000000000..fffdf30554f --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/simple.kt @@ -0,0 +1,20 @@ +// FIR_IDENTICAL +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// FIR_IDENTICAL + +class C: suspend () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI: suspend () -> Unit { +} + +interface I: suspend () -> Unit { +} + +object O: suspend () -> Unit { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.fir.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.fir.kt new file mode 100644 index 00000000000..6d87b464d77 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS +import kotlin.coroutines.* + +class C: SuspendFunction0, () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI: SuspendFunction0, () -> Unit { +} + +interface I: SuspendFunction0, () -> Unit { +} + +object O: SuspendFunction0, () -> Unit { + override suspend fun invoke() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt new file mode 100644 index 00000000000..0feff2d10ff --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS +import kotlin.coroutines.* + +class C: SuspendFunction0, () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI: SuspendFunction0, () -> Unit { +} + +interface I: SuspendFunction0, () -> Unit { +} + +object O: SuspendFunction0, () -> Unit { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.fir.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.fir.kt new file mode 100644 index 00000000000..a0fd4837d67 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.fir.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +import kotlin.coroutines.* + +abstract class CSuper: () -> Unit + +class C: CSuper(), SuspendFunction0 { + override suspend fun invoke() { + } +} + +object O: CSuper(), SuspendFunction0 { + override suspend fun invoke() { + } +} + +abstract class SCSuper: SuspendFunction0 + +class C1: SCSuper(), () -> Unit { + override suspend fun invoke() { + } +} + +object O1: SCSuper(), () -> Unit { + override suspend fun invoke() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt new file mode 100644 index 00000000000..59556d8ed4c --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt @@ -0,0 +1,29 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +import kotlin.coroutines.* + +abstract class CSuper: () -> Unit + +class C: CSuper(), SuspendFunction0 { + override suspend fun invoke() { + } +} + +object O: CSuper(), SuspendFunction0 { + override suspend fun invoke() { + } +} + +abstract class SCSuper: SuspendFunction0 + +class C1: SCSuper(), () -> Unit { + override suspend fun invoke() { + } +} + +object O1: SCSuper(), () -> Unit { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.fir.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.fir.kt new file mode 100644 index 00000000000..a13f5f0ce62 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.fir.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +import kotlin.coroutines.* + +fun interface FISuper: () -> Unit + +class C: SuspendFunction0, FISuper { + override suspend fun invoke() { + } +} + +fun interface FI: SuspendFunction0, FISuper { +} + +interface I: SuspendFunction0, FISuper { +} + +object O: SuspendFunction0, FISuper { + override suspend fun invoke() { + } +} + +fun interface SFISuper: SuspendFunction0 + +class C1: SFISuper, () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI1: SFISuper, () -> Unit { +} + +interface I1: SFISuper, () -> Unit { +} + +object O1: SFISuper, () -> Unit { + override suspend fun invoke() { + } +} + +class C2: SFISuper, FISuper { + override suspend fun invoke() { + } +} + +fun interface FI2: SFISuper, FISuper { +} + +interface I2: SFISuper, FISuper { +} + +object O2: SFISuper, FISuper { + override suspend fun invoke() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt new file mode 100644 index 00000000000..8272c7b6961 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +import kotlin.coroutines.* + +fun interface FISuper: () -> Unit + +class C: SuspendFunction0, FISuper { + override suspend fun invoke() { + } +} + +fun interface FI: SuspendFunction0, FISuper { +} + +interface I: SuspendFunction0, FISuper { +} + +object O: SuspendFunction0, FISuper { + override suspend fun invoke() { + } +} + +fun interface SFISuper: SuspendFunction0 + +class C1: SFISuper, () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI1: SFISuper, () -> Unit { +} + +interface I1: SFISuper, () -> Unit { +} + +object O1: SFISuper, () -> Unit { + override suspend fun invoke() { + } +} + +class C2: SFISuper, FISuper { + override suspend fun invoke() { + } +} + +fun interface FI2: SFISuper, FISuper { +} + +interface I2: SFISuper, FISuper { +} + +object O2: SFISuper, FISuper { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.fir.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.fir.kt new file mode 100644 index 00000000000..09e83a5b688 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.fir.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +import kotlin.coroutines.* + +interface ISuper: () -> Unit + +class C: SuspendFunction0, ISuper { + override suspend fun invoke() { + } +} + +fun interface FI: SuspendFunction0, ISuper { +} + +interface I: SuspendFunction0, ISuper { +} + +object O: SuspendFunction0, ISuper { + override suspend fun invoke() { + } +} + +interface SISuper: SuspendFunction0 + +class C1: SISuper, () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI1: SISuper, () -> Unit { +} + +interface I1: SISuper, () -> Unit { +} + +object O1: SISuper, () -> Unit { + override suspend fun invoke() { + } +} + +class C2: SISuper, ISuper { + override suspend fun invoke() { + } +} + +fun interface FI2: SISuper, ISuper { +} + +interface I2: SISuper, ISuper { +} + +object O2: SISuper, ISuper { + override suspend fun invoke() { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt new file mode 100644 index 00000000000..5894ad8c6b9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt @@ -0,0 +1,57 @@ +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS + +import kotlin.coroutines.* + +interface ISuper: () -> Unit + +class C: SuspendFunction0, ISuper { + override suspend fun invoke() { + } +} + +fun interface FI: SuspendFunction0, ISuper { +} + +interface I: SuspendFunction0, ISuper { +} + +object O: SuspendFunction0, ISuper { + override suspend fun invoke() { + } +} + +interface SISuper: SuspendFunction0 + +class C1: SISuper, () -> Unit { + override suspend fun invoke() { + } +} + +fun interface FI1: SISuper, () -> Unit { +} + +interface I1: SISuper, () -> Unit { +} + +object O1: SISuper, () -> Unit { + override suspend fun invoke() { + } +} + +class C2: SISuper, ISuper { + override suspend fun invoke() { + } +} + +fun interface FI2: SISuper, ISuper { +} + +interface I2: SISuper, ISuper { +} + +object O2: SISuper, ISuper { + override suspend fun invoke() { + } +} diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/simple.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/simple.kt new file mode 100644 index 00000000000..26961e5a2cd --- /dev/null +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/simple.kt @@ -0,0 +1,22 @@ +// FIR_IDENTICAL +// !LANGUAGE: +SuspendFunctionAsSupertype +// SKIP_TXT +// FIR_IDENTICAL + +import kotlin.coroutines.* + +class C: SuspendFunction0 { + override suspend fun invoke() { + } +} + +fun interface FI: SuspendFunction0 { +} + +interface I: SuspendFunction0 { +} + +object O: SuspendFunction0 { + override suspend fun invoke() { + } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index aa9a57b2819..bc824bf062b 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -5686,6 +5686,136 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/coroutines/callableReference/outsideSuspend.kt"); } } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype") + @TestDataPath("$PROJECT_ROOT") + public class SuspendFunctionAsSupertype { + @Test + public void testAllFilesPresentInSuspendFunctionAsSupertype() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN") + @TestDataPath("$PROJECT_ROOT") + public class KSuspendFunctionN { + @Test + public void testAllFilesPresentInKSuspendFunctionN() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypes.kt") + public void testMixingSuspendAndNonSuspendSupertypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperFunInterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperinterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/kSuspendFunctionN/simple.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple") + @TestDataPath("$PROJECT_ROOT") + public class Simple { + @Test + public void testAllFilesPresentInSimple() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypes.kt") + public void testMixingSuspendAndNonSuspendSupertypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperFunInterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperinterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/simple.kt"); + } + } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN") + @TestDataPath("$PROJECT_ROOT") + public class SuspendFunctionN { + @Test + public void testAllFilesPresentInSuspendFunctionN() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypes.kt") + public void testMixingSuspendAndNonSuspendSupertypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperClass() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperFunInterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt"); + } + + @Test + @TestMetadata("mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt") + public void testMixingSuspendAndNonSuspendSupertypesThruSuperinterface() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/simple.kt"); + } + } + } } @Nested diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 2dda97297e9..c4a18c418be 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -9366,6 +9366,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/coroutines/suspendFunImportedFromObject.kt"); } + @Test + @TestMetadata("suspendFunctionAsSupertype.kt") + public void testSuspendFunctionAsSupertype() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt"); + } + @Test @TestMetadata("suspendFunctionMethodReference.kt") public void testSuspendFunctionMethodReference() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 6d44085b095..1e7c041a16d 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -9366,6 +9366,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/coroutines/suspendFunImportedFromObject.kt"); } + @Test + @TestMetadata("suspendFunctionAsSupertype.kt") + public void testSuspendFunctionAsSupertype() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt"); + } + @Test @TestMetadata("suspendFunctionMethodReference.kt") public void testSuspendFunctionMethodReference() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 3befa4f2c91..3bf1d321e38 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -6801,6 +6801,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/coroutines/kt38099.kt"); } + @TestMetadata("suspendFunctionAsSupertype.kt") + public void ignoreSuspendFunctionAsSupertype() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt"); + } + private void runTest(String testDataFilePath) throws Exception { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index d3a91f3790a..5183918de9d 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -205,6 +205,8 @@ enum class LanguageFeature( DefinitelyNotNullTypeParameters(KOTLIN_1_6), ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated(KOTLIN_1_6, kind = BUG_FIX), + SuspendFunctionAsSupertype(KOTLIN_1_6), + // Temporarily disabled, see KT-27084/KT-22379 SoundSmartcastFromLoopConditionForLoopAssignedVariables(sinceVersion = null, kind = BUG_FIX), diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index d3d352d72fa..22cdbf80bf9 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -6558,6 +6558,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/coroutines/suspendFunImportedFromObject.kt"); } + @TestMetadata("suspendFunctionAsSupertype.kt") + public void testSuspendFunctionAsSupertype() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt"); + } + @TestMetadata("suspendFunctionMethodReference.kt") public void testSuspendFunctionMethodReference() throws Exception { runTest("compiler/testData/codegen/box/coroutines/suspendFunctionMethodReference.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index a18b10ab2b5..9d4c9726b2c 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -5969,6 +5969,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/suspendFunImportedFromObject.kt"); } + @TestMetadata("suspendFunctionAsSupertype.kt") + public void testSuspendFunctionAsSupertype() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt"); + } + @TestMetadata("suspendFunctionMethodReference.kt") public void testSuspendFunctionMethodReference() throws Exception { runTest("compiler/testData/codegen/box/coroutines/suspendFunctionMethodReference.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 62daaf07683..444c18b4adc 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -5969,6 +5969,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/suspendFunImportedFromObject.kt"); } + @TestMetadata("suspendFunctionAsSupertype.kt") + public void testSuspendFunctionAsSupertype() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt"); + } + @TestMetadata("suspendFunctionMethodReference.kt") public void testSuspendFunctionMethodReference() throws Exception { runTest("compiler/testData/codegen/box/coroutines/suspendFunctionMethodReference.kt");