From 22d202e657cc7283e5da3f3ccd138918c068d291 Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Wed, 28 Jul 2021 19:35:56 +0300 Subject: [PATCH] [JS IR] Add test on type check of suspend functional interfaces ^KT-46204 fixed --- ...pendFunctionAsSupertypeIsCheckWithArity.kt | 59 +++++++++++++++++++ .../IrJsCodegenBoxES6TestGenerated.java | 5 ++ .../IrJsCodegenBoxTestGenerated.java | 5 ++ .../semantics/JsCodegenBoxTestGenerated.java | 5 ++ 4 files changed, 74 insertions(+) create mode 100644 compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheckWithArity.kt diff --git a/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheckWithArity.kt b/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheckWithArity.kt new file mode 100644 index 00000000000..d846d76d8ba --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheckWithArity.kt @@ -0,0 +1,59 @@ +// KJS_WITH_FULL_RUNTIME +// TARGET_BACKEND: JS +// !LANGUAGE: +SuspendFunctionAsSupertype + +import kotlin.coroutines.* + +class C: suspend () -> Unit { + override suspend fun invoke() { + } +} + +interface I: suspend () -> Unit {} + +fun interface FI: suspend () -> Unit {} + +interface I2: suspend (Int) -> Unit, suspend (Int, Int) -> Unit { + +} + +@Suppress("INCOMPATIBLE_TYPES") +fun box(): String { + val c = C() + if (c !is SuspendFunction0<*>) return "FAIL 1" + if (c is SuspendFunction1<*, *>) return "FAIL 2" + + val i = object : I { + override suspend fun invoke() { + } + } + if (i !is SuspendFunction0) return "FAIL 3" + if (i is SuspendFunction1<*, *>) return "FAIL 4" + + val fi = object : FI { + override suspend fun invoke() { + } + } + if (fi !is SuspendFunction0) return "FAIL 5" + if (fi is SuspendFunction1<*, *>) return "FAIL 6" + + val o = object : suspend () -> Unit { + override suspend fun invoke() { + } + } + if (o !is SuspendFunction0) return "FAIL 7" + if (o is SuspendFunction1<*, *>) return "FAIL 8" + + val i2 = object : I2 { + override suspend fun invoke(i1: Int) { + } + + override suspend fun invoke(i1: Int, i2: Int) { + } + } + if (i2 !is SuspendFunction1<*, *>) return "FAIL 9" + if (i2 !is SuspendFunction2<*, *, *>) return "FAIL 10" + if (i2 is SuspendFunction3<*, *, *, *>) return "FAIL 11" + + return "OK" +} \ No newline at end of file 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 d4fb186219a..f3a84849e14 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 @@ -7060,6 +7060,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendDestructuringInLambdas.kt"); } + @TestMetadata("suspendFunctionAsSupertypeIsCheckWithArity.kt") + public void testSuspendFunctionAsSupertypeIsCheckWithArity() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheckWithArity.kt"); + } + @TestMetadata("suspendFunctionIsAs.kt") public void testSuspendFunctionIsAs() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.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 a3cad51b6c5..8dda8e00d3c 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 @@ -6466,6 +6466,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendDestructuringInLambdas.kt"); } + @TestMetadata("suspendFunctionAsSupertypeIsCheckWithArity.kt") + public void testSuspendFunctionAsSupertypeIsCheckWithArity() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheckWithArity.kt"); + } + @TestMetadata("suspendFunctionIsAs.kt") public void testSuspendFunctionIsAs() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.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 462e344897c..00cf86f8d0f 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 @@ -6466,6 +6466,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendDestructuringInLambdas.kt"); } + @TestMetadata("suspendFunctionAsSupertypeIsCheckWithArity.kt") + public void testSuspendFunctionAsSupertypeIsCheckWithArity() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheckWithArity.kt"); + } + @TestMetadata("suspendFunctionIsAs.kt") public void testSuspendFunctionIsAs() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionIsAs.kt");