[FIR] Build resolved argument list for augmented array assignment get call

This lets us get rid of some fallback code in FIR2IR that handles
unresolved argument lists.
After this, we should have an invariant that all non-empty argument
lists are resolved when FIR2IR runs.

#KT-66124
This commit is contained in:
Kirill Rakhman
2024-03-04 13:37:10 +01:00
committed by Space Team
parent 8443daf78d
commit 454ef4ae46
2 changed files with 20 additions and 32 deletions
@@ -892,26 +892,12 @@ class CallAndReferenceGenerator(
if (argumentsCount <= valueArgumentsCount) { if (argumentsCount <= valueArgumentsCount) {
apply { apply {
val (valueParameters, argumentMapping, substitutor) = extractArgumentsMapping(call) val (valueParameters, argumentMapping, substitutor) = extractArgumentsMapping(call)
if (argumentMapping != null && (visitor.annotationMode || argumentMapping.isNotEmpty())) { if (argumentMapping != null && (visitor.annotationMode || argumentMapping.isNotEmpty()) && valueParameters != null) {
if (valueParameters != null) {
return applyArgumentsWithReorderingIfNeeded( return applyArgumentsWithReorderingIfNeeded(
argumentMapping, valueParameters, substitutor, contextReceiverCount, call, argumentMapping, valueParameters, substitutor, contextReceiverCount, call,
) )
} }
} check(argumentsCount == 0) { "Non-empty unresolved argument list." }
// Case without argument mapping (deserialized annotation)
// TODO: support argument mapping in deserialized annotations and remove me
for ((index, argument) in call.arguments.withIndex()) {
val valueParameter = when (argument) {
is FirNamedArgumentExpression -> valueParameters?.find { it.name == argument.name }
else -> null
} ?: valueParameters?.get(index)
val argumentExpression = convertArgument(argument, valueParameter, substitutor)
putValueArgument(
(valueParameters?.indexOf(valueParameter)?.takeIf { it >= 0 } ?: index) + contextReceiverCount,
argumentExpression
)
}
} }
} else { } else {
val calleeSymbol = (this as? IrCallImpl)?.symbol val calleeSymbol = (this as? IrCallImpl)?.symbol
@@ -1635,10 +1635,9 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
dispatchReceiver = lhsGetCall.dispatchReceiver dispatchReceiver = lhsGetCall.dispatchReceiver
} }
calleeReference = lhsGetCall.calleeReference calleeReference = lhsGetCall.calleeReference
argumentList = buildArgumentList {
var i = 0 var i = 0
for (argument in lhsGetCall.argumentList.arguments) { val newMapping = (lhsGetCall.argumentList as FirResolvedArgumentList).mapping.mapKeysTo(LinkedHashMap()) { (argument) ->
arguments += if (argument is FirVarargArgumentsExpression) { if (argument is FirVarargArgumentsExpression) {
buildVarargArgumentsExpression { buildVarargArgumentsExpression {
val varargSize = argument.arguments.size val varargSize = argument.arguments.size
arguments += indicesQualifiedAccessForGet.subList(i, i + varargSize) arguments += indicesQualifiedAccessForGet.subList(i, i + varargSize)
@@ -1651,7 +1650,10 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
indicesQualifiedAccessForGet[i++] indicesQualifiedAccessForGet[i++]
} }
} }
} argumentList = buildResolvedArgumentList(
lhsGetCall.argumentList,
newMapping,
)
origin = FirFunctionCallOrigin.Operator origin = FirFunctionCallOrigin.Operator
coneTypeOrNull = lhsGetCall.resolvedType coneTypeOrNull = lhsGetCall.resolvedType
} }