Generate SuspendFunction marker interface if supertype is suspend

Otherwise, is/as checks will not work.
 #KT-18707
This commit is contained in:
Ilmir Usmanov
2021-04-28 00:01:25 +02:00
committed by TeamCityServer
parent 5d296a01c2
commit cb89bd0e13
6 changed files with 77 additions and 1 deletions
@@ -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 {
@@ -279,8 +279,12 @@ internal fun IrTypeMapper.mapClassSignature(irClass: IrClass, type: Type): JvmCl
}
sw.writeSuperclassEnd()
val superInterfaces = LinkedHashSet<String>()
val kotlinMarkerInterfaces = LinkedHashSet<String>()
if (irClass.superTypes.any { it.isSuspendFunction() || it.isKSuspendFunction() }) {
kotlinMarkerInterfaces.add("kotlin/coroutines/jvm/internal/SuspendFunction")
}
val superInterfaces = LinkedHashSet<String>()
for (superType in irClass.superTypes) {
val superClass = superType.safeAs<IrSimpleType>()?.classifier?.safeAs<IrClassSymbol>()?.owner ?: continue
if (superClass.isJvmInterface) {
@@ -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<Unit>) 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<Unit>) 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<Unit>) return "FAIL 10"
if (o !is Function1<*, *>) return "FAIL 11"
if (o is SuspendFunction1<*, *>) return "FAIL 12"
return "OK"
}
@@ -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 {
@@ -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 {
@@ -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);
}