From 2d4c94a115f505c12bd2f97b091cb4c9a3440e4b Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Thu, 8 Sep 2022 15:16:39 +0200 Subject: [PATCH] [K/N] Add test for inter-module suspend function override --- .../FirBlackBoxCodegenTestGenerated.java | 6 +++ .../multiModule/inheritFromAnotherModule.kt | 49 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 +++ .../IrBlackBoxCodegenTestGenerated.java | 6 +++ .../LightAnalysisModeTestGenerated.java | 5 ++ .../js/test/JsCodegenBoxTestGenerated.java | 6 +++ .../test/ir/IrJsCodegenBoxTestGenerated.java | 6 +++ .../IrCodegenBoxWasmTestGenerated.java | 5 ++ .../NativeCodegenBoxTestGenerated.java | 6 +++ 9 files changed, 95 insertions(+) create mode 100644 compiler/testData/codegen/box/coroutines/multiModule/inheritFromAnotherModule.kt 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 62e5b2f9ab8..a78cbe8fb78 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 @@ -12638,6 +12638,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("inheritFromAnotherModule.kt") + public void testInheritFromAnotherModule() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/multiModule/inheritFromAnotherModule.kt"); + } + @Test @TestMetadata("inlineCrossModule.kt") public void testInlineCrossModule() throws Exception { diff --git a/compiler/testData/codegen/box/coroutines/multiModule/inheritFromAnotherModule.kt b/compiler/testData/codegen/box/coroutines/multiModule/inheritFromAnotherModule.kt new file mode 100644 index 00000000000..80a2e260280 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/multiModule/inheritFromAnotherModule.kt @@ -0,0 +1,49 @@ +// WITH_STDLIB +// WITH_COROUTINES + +// MODULE: lib +// FILE: lib.kt + +class AAA +class ZZZ + +open class A { + // function signatures are chosen in a way, that their order for Native will change, if suspend is not lowered correctly + open suspend fun f(x:Int) = 1 + open fun f(x:AAA) = 2 + open fun f(x:ZZZ) = 3 +} + +// MODULE: main(lib) +// FILE: main.kt + +import kotlin.coroutines.* +import helpers.* + + +class ImplementA : A(){ + override suspend fun f(x:Int) = 4 +} + +class NotImplementA : A() {} + + +fun runF(x: A, f: suspend A.() -> Int) : Int { + var res: Int = -1 + f.startCoroutine(x, handleResultContinuation { + res = it + }) + return res +} + +fun box() : String { + val x = if (true) ImplementA() else A() // to avoid devirtualization + if (x.f(AAA()) != 2) return "FAIL 1" + if (x.f(ZZZ()) != 3) return "FAIL 2" + if (runF(x, { f(1) }) != 4) return "FAIL 3" + val y = if (true) NotImplementA() else A() // to avoid devirtualization + if (y.f(AAA()) != 2) return "FAIL 4" + if (y.f(ZZZ()) != 3) return "FAIL 5" + if (runF(y, { f(1) }) != 1) return "FAIL 6" + return "OK" +} 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 7a9e7c45dd0..0758f4afed5 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 @@ -12464,6 +12464,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test + @TestMetadata("inheritFromAnotherModule.kt") + public void testInheritFromAnotherModule() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/multiModule/inheritFromAnotherModule.kt"); + } + @Test @TestMetadata("inlineCrossModule.kt") public void testInlineCrossModule() 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 c153709b90c..773e95e8c37 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 @@ -12638,6 +12638,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("inheritFromAnotherModule.kt") + public void testInheritFromAnotherModule() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/multiModule/inheritFromAnotherModule.kt"); + } + @Test @TestMetadata("inlineCrossModule.kt") public void testInlineCrossModule() 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 775609c9b61..3c51845e235 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -10010,6 +10010,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("inheritFromAnotherModule.kt") + public void testInheritFromAnotherModule() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/multiModule/inheritFromAnotherModule.kt"); + } + @TestMetadata("inlineCrossModule.kt") public void testInlineCrossModule() throws Exception { runTest("compiler/testData/codegen/box/coroutines/multiModule/inlineCrossModule.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index 8c4c4ae7dd7..25ab876d442 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -9268,6 +9268,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); } + @Test + @TestMetadata("inheritFromAnotherModule.kt") + public void testInheritFromAnotherModule() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/multiModule/inheritFromAnotherModule.kt"); + } + @Test @TestMetadata("inlineCrossModule.kt") public void testInlineCrossModule() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 121ecbd1561..d7b1b64582c 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -9358,6 +9358,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test + @TestMetadata("inheritFromAnotherModule.kt") + public void testInheritFromAnotherModule() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/multiModule/inheritFromAnotherModule.kt"); + } + @Test @TestMetadata("inlineCrossModule.kt") public void testInlineCrossModule() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index b176c74f046..cf1ab1d0cad 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -8245,6 +8245,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } + @TestMetadata("inheritFromAnotherModule.kt") + public void testInheritFromAnotherModule() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/multiModule/inheritFromAnotherModule.kt"); + } + @TestMetadata("inlineCrossModule.kt") public void testInlineCrossModule() throws Exception { runTest("compiler/testData/codegen/box/coroutines/multiModule/inlineCrossModule.kt"); diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 3479d01af48..ac5a5d49837 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -10266,6 +10266,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); } + @Test + @TestMetadata("inheritFromAnotherModule.kt") + public void testInheritFromAnotherModule() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/multiModule/inheritFromAnotherModule.kt"); + } + @Test @TestMetadata("inlineCrossModule.kt") public void testInlineCrossModule() throws Exception {