[K/N] Make classes generated from λs that use generic parameters generic

Previously, a function reference that used generic parameters from its
outer scope was lowered into a top-level non-generic subclass of
`FunctionN`, with `FunctionN` type arguments referencing type parameters
not present in the scope anymore. This sometimes resulted in generating
malformed mangled names.

From now on the generated subclass of `FunctionN` is generic. The needed
type arguments are passed upon instantiation, when the relevant generic
parameters are present in the scope.
This commit is contained in:
Sergej Jaskiewicz
2023-01-10 17:19:13 +01:00
committed by Space Team
parent 0e1350f464
commit 4a2a77d9b9
13 changed files with 133 additions and 24 deletions
@@ -13,11 +13,12 @@ import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
import org.jetbrains.kotlin.ir.types.impl.IrTypeAbbreviationImpl
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
/* After moving an IrElement, some type parameter references within it may become out of scope.
This remapper restores validity by redirecting those references to new type parameters.
/**
* After moving an [org.jetbrains.kotlin.ir.IrElement], some type parameter references within it may become out of scope.
* This remapper restores validity by redirecting those references to new type parameters.
*/
class IrTypeParameterRemapper(
val typeParameterMap: Map<IrTypeParameter, IrTypeParameter>
private val typeParameterMap: Map<IrTypeParameter, IrTypeParameter>
) : TypeRemapper {
override fun enterScope(irTypeParametersContainer: IrTypeParametersContainer) {}
override fun leaveScope() {}
@@ -56,4 +57,4 @@ class IrTypeParameterRemapper(
).apply {
annotations.forEach { it.remapTypes(this@IrTypeParameterRemapper) }
}
}
}