Add a utility function to compute type substitutions for call
This commit is contained in:
committed by
max-kammerer
parent
d61b276ebf
commit
a7b31ba42b
+1
-7
@@ -378,12 +378,6 @@ class ExpressionCodegen(
|
||||
}
|
||||
|
||||
callGenerator.beforeValueParametersStart()
|
||||
val typeParameters = if (callee is IrConstructor)
|
||||
callee.parentAsClass.typeParameters + callee.typeParameters
|
||||
else
|
||||
callee.typeParameters
|
||||
val typeArguments = (0 until typeParameters.size).map { expression.getTypeArgument(it)!! }
|
||||
val typeSubstitutionMap = typeParameters.map { it.symbol }.zip(typeArguments).toMap()
|
||||
expression.symbol.owner.valueParameters.forEachIndexed { i, irParameter ->
|
||||
val arg = expression.getValueArgument(i)
|
||||
val parameterType = callable.valueParameterTypes[i]
|
||||
@@ -429,7 +423,7 @@ class ExpressionCodegen(
|
||||
}
|
||||
|
||||
return when {
|
||||
returnType.substitute(typeSubstitutionMap).isNothing() -> {
|
||||
returnType.substitute(expression.typeSubstitutionMap).isNothing() -> {
|
||||
mv.aconst(null)
|
||||
mv.athrow()
|
||||
immaterialUnitValue
|
||||
|
||||
+1
-7
@@ -131,13 +131,7 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext)
|
||||
private val parameterTypes = (irFunctionReference.type as IrSimpleType).arguments.map { (it as IrTypeProjection).type }
|
||||
private val argumentTypes = parameterTypes.dropLast(1)
|
||||
|
||||
private val typeParameters = if (callee is IrConstructor)
|
||||
callee.parentAsClass.typeParameters + callee.typeParameters
|
||||
else
|
||||
callee.typeParameters
|
||||
private val typeArgumentsMap = typeParameters.associate { typeParam ->
|
||||
typeParam.symbol to irFunctionReference.getTypeArgument(typeParam.index)!!
|
||||
}
|
||||
private val typeArgumentsMap = irFunctionReference.typeSubstitutionMap
|
||||
|
||||
private val functionReferenceClass = buildClass {
|
||||
setSourceRange(irFunctionReference)
|
||||
|
||||
@@ -590,3 +590,20 @@ val IrDeclaration.file: IrFile
|
||||
else -> TODO("Unexpected declaration parent")
|
||||
}
|
||||
}
|
||||
|
||||
val IrFunction.allTypeParameters: List<IrTypeParameter>
|
||||
get() = if (this is IrConstructor)
|
||||
parentAsClass.typeParameters + typeParameters
|
||||
else
|
||||
typeParameters
|
||||
|
||||
fun IrMemberAccessExpression.getTypeSubstitutionMap(irFunction: IrFunction): Map<IrTypeParameterSymbol, IrType> =
|
||||
irFunction.allTypeParameters.withIndex().associate {
|
||||
it.value.symbol to getTypeArgument(it.index)!!
|
||||
}
|
||||
|
||||
val IrFunctionReference.typeSubstitutionMap: Map<IrTypeParameterSymbol, IrType>
|
||||
get() = getTypeSubstitutionMap(symbol.owner)
|
||||
|
||||
val IrFunctionAccessExpression.typeSubstitutionMap: Map<IrTypeParameterSymbol, IrType>
|
||||
get() = getTypeSubstitutionMap(symbol.owner)
|
||||
|
||||
Reference in New Issue
Block a user