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 af3b915b6b4..4278b2f793b 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 @@ -9819,6 +9819,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendDestructuringInLambdas.kt"); } + @Test + @TestMetadata("suspendFunctionAsSupertypeIsCheck.kt") + public void testSuspendFunctionAsSupertypeIsCheck() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheck.kt"); + } + @Test @TestMetadata("suspendFunctionIsAs.kt") public void testSuspendFunctionIsAs() throws Exception { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt index b2f9b4cb686..53a8583f62b 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt @@ -279,8 +279,12 @@ internal fun IrTypeMapper.mapClassSignature(irClass: IrClass, type: Type): JvmCl } sw.writeSuperclassEnd() - val superInterfaces = LinkedHashSet() val kotlinMarkerInterfaces = LinkedHashSet() + if (irClass.superTypes.any { it.isSuspendFunction() || it.isKSuspendFunction() }) { + kotlinMarkerInterfaces.add("kotlin/coroutines/jvm/internal/SuspendFunction") + } + + val superInterfaces = LinkedHashSet() for (superType in irClass.superTypes) { val superClass = superType.safeAs()?.classifier?.safeAs()?.owner ?: continue if (superClass.isJvmInterface) { diff --git a/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheck.kt b/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheck.kt new file mode 100644 index 00000000000..7f68bf8d651 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheck.kt @@ -0,0 +1,49 @@ +// WITH_RUNTIME +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// !LANGUAGE: +SuspendFunctionAsSupertype + +import kotlin.coroutines.* + +class C: suspend () -> Unit { + override suspend fun invoke() { + } +} + +interface I: suspend () -> Unit {} + +fun interface FI: suspend () -> Unit {} + +@Suppress("INCOMPATIBLE_TYPES") +fun box(): String { + val c = C() + if (c !is SuspendFunction0<*>) return "FAIL 1" + if (c !is Function1<*, *>) return "FAIL 2" + if (c is SuspendFunction1<*, *>) return "FAIL 3" + + val i = object : I { + override suspend fun invoke() { + } + } + if (i !is SuspendFunction0) return "FAIL 4" + if (i !is Function1<*, *>) return "FAIL 5" + if (i is SuspendFunction1<*, *>) return "FAIL 6" + + val fi = object : FI { + override suspend fun invoke() { + } + } + if (fi !is SuspendFunction0) return "FAIL 7" + if (fi !is Function1<*, *>) return "FAIL 8" + if (fi is SuspendFunction1<*, *>) return "FAIL 9" + + val o = object : suspend () -> Unit { + override suspend fun invoke() { + } + } + if (o !is SuspendFunction0) return "FAIL 10" + if (o !is Function1<*, *>) return "FAIL 11" + if (o is SuspendFunction1<*, *>) return "FAIL 12" + + return "OK" +} \ No newline at end of file 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 7c3218bb87d..89ed7329b02 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 @@ -9819,6 +9819,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendDestructuringInLambdas.kt"); } + @Test + @TestMetadata("suspendFunctionAsSupertypeIsCheck.kt") + public void testSuspendFunctionAsSupertypeIsCheck() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheck.kt"); + } + @Test @TestMetadata("suspendFunctionIsAs.kt") public void testSuspendFunctionIsAs() 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 7065c7f46a3..bf06950b4f1 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 @@ -9819,6 +9819,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendDestructuringInLambdas.kt"); } + @Test + @TestMetadata("suspendFunctionAsSupertypeIsCheck.kt") + public void testSuspendFunctionAsSupertypeIsCheck() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheck.kt"); + } + @Test @TestMetadata("suspendFunctionIsAs.kt") public void testSuspendFunctionIsAs() 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 a0d6f97f184..4de37d7755f 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -7647,6 +7647,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface.kt"); } + @TestMetadata("suspendFunctionAsSupertypeIsCheck.kt") + public void ignoreSuspendFunctionAsSupertypeIsCheck() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/suspendFunctionAsSupertypeIsCheck.kt"); + } + private void runTest(String testDataFilePath) throws Exception { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); }