JVM IR: Copy type parameters from outer class to suspendImpl
Previously we copied only type parameters from containing class, but we need to do that for outer classes as well. #KT-55125
This commit is contained in:
committed by
Space Team
parent
5cd817955b
commit
b262070922
+6
@@ -10807,6 +10807,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/coroutines/suspendImplTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendImplTypeParametersOuterClass.kt")
|
||||
public void testSuspendImplTypeParametersOuterClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/suspendImplTypeParametersOuterClass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendInCycle.kt")
|
||||
public void testSuspendInCycle() throws Exception {
|
||||
|
||||
+2
-1
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.defaultType
|
||||
import org.jetbrains.kotlin.ir.types.extractTypeParameters
|
||||
import org.jetbrains.kotlin.ir.types.typeWith
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
@@ -226,7 +227,7 @@ private class AddContinuationLowering(context: JvmBackendContext) : SuspendLower
|
||||
JavaDescriptorVisibilities.PACKAGE_VISIBILITY,
|
||||
isFakeOverride = false,
|
||||
copyMetadata = false,
|
||||
typeParametersFromContext = irFunction.parentAsClass.typeParameters,
|
||||
typeParametersFromContext = extractTypeParameters(irFunction.parentAsClass)
|
||||
)
|
||||
static.body = irFunction.moveBodyTo(static)
|
||||
// Fixup dispatch parameter to outer class
|
||||
|
||||
@@ -1281,7 +1281,7 @@ private fun IrSimpleFunction.copyAndRenameConflictingTypeParametersFrom(
|
||||
val existingNames =
|
||||
(contextParameters.map { it.name.asString() } + existingParameters.map { it.name.asString() }).toMutableSet()
|
||||
|
||||
contextParameters.forEach { contextType ->
|
||||
contextParameters.forEachIndexed { i, contextType ->
|
||||
val newName = if (existingParameters.any { it.name.asString() == contextType.name.asString() }) {
|
||||
val newNamePrefix = contextType.name.asString() + "_I"
|
||||
val newName = newNamePrefix + generateSequence(1) { x -> x + 1 }.first { n ->
|
||||
@@ -1295,6 +1295,7 @@ private fun IrSimpleFunction.copyAndRenameConflictingTypeParametersFrom(
|
||||
|
||||
newParameters.add(buildTypeParameter(this) {
|
||||
updateFrom(contextType)
|
||||
index = i
|
||||
name = Name.identifier(newName)
|
||||
})
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WITH_STDLIB
|
||||
// FULL_JDK
|
||||
|
||||
class Outer<U> {
|
||||
inner abstract class AbstractPersistence<T> {
|
||||
open suspend fun fetch(identifier: U): T? = null
|
||||
}
|
||||
|
||||
fun foo(): String = AbstractPersistence::class.java.declaredMethods
|
||||
.single { it.name.contains("\$suspendImpl") }
|
||||
.toGenericString()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val genericString = Outer<Unit>().foo()
|
||||
if (!genericString.startsWith("static <T,U>")) {
|
||||
return genericString
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -10807,6 +10807,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/coroutines/suspendImplTypeParameters.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendImplTypeParametersOuterClass.kt")
|
||||
public void testSuspendImplTypeParametersOuterClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/suspendImplTypeParametersOuterClass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendInCycle.kt")
|
||||
public void testSuspendInCycle() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user