JVM IR: Copy type parameters from class to suspendImpl

These type parameters where used in function parameters,
but since suspendImpl is static function, it has no access
to class type parameters. Solution is to copy them to
the function itself.

 #KT-55125 Fixed
This commit is contained in:
Ilmir Usmanov
2022-11-30 19:29:55 +01:00
committed by Space Team
parent 94f1c579df
commit 901ff06e90
4 changed files with 34 additions and 1 deletions
@@ -10765,6 +10765,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/coroutines/suspendImplBridge.kt");
}
@Test
@TestMetadata("suspendImplTypeParameters.kt")
public void testSuspendImplTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendImplTypeParameters.kt");
}
@Test
@TestMetadata("suspendInCycle.kt")
public void testSuspendInCycle() throws Exception {
@@ -225,7 +225,8 @@ private class AddContinuationLowering(context: JvmBackendContext) : SuspendLower
else
JavaDescriptorVisibilities.PACKAGE_VISIBILITY,
isFakeOverride = false,
copyMetadata = false
copyMetadata = false,
typeParametersFromContext = irFunction.parentAsClass.typeParameters,
)
static.body = irFunction.moveBodyTo(static)
// Fixup dispatch parameter to outer class
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM_IR
// WITH_STDLIB
// FULL_JDK
abstract class AbstractPersistence<T, U> {
open suspend fun fetch(identifier: U): T? = null
}
fun box(): String {
val genericString =
AbstractPersistence::class.java.declaredMethods
.single { it.name.contains("\$suspendImpl") }
.toGenericString()
if (!genericString.startsWith("static <T,U>")) {
return genericString
}
return "OK"
}
@@ -10765,6 +10765,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/coroutines/suspendImplBridge.kt");
}
@Test
@TestMetadata("suspendImplTypeParameters.kt")
public void testSuspendImplTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendImplTypeParameters.kt");
}
@Test
@TestMetadata("suspendInCycle.kt")
public void testSuspendInCycle() throws Exception {