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:
Ilmir Usmanov
2023-02-07 16:01:10 +01:00
committed by Space Team
parent 5cd817955b
commit b262070922
5 changed files with 38 additions and 2 deletions
@@ -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)
})
}