[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) {
apply {
val (valueParameters, argumentMapping, substitutor) = extractArgumentsMapping(call)
if (argumentMapping != null && (visitor.annotationMode || argumentMapping.isNotEmpty())) {
if (valueParameters != null) {
return applyArgumentsWithReorderingIfNeeded(
argumentMapping, valueParameters, substitutor, contextReceiverCount, call,
)
}
}
// 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
if (argumentMapping != null && (visitor.annotationMode || argumentMapping.isNotEmpty()) && valueParameters != null) {
return applyArgumentsWithReorderingIfNeeded(
argumentMapping, valueParameters, substitutor, contextReceiverCount, call,
)
}
check(argumentsCount == 0) { "Non-empty unresolved argument list." }
}
} else {
val calleeSymbol = (this as? IrCallImpl)?.symbol
@@ -1635,23 +1635,25 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
dispatchReceiver = lhsGetCall.dispatchReceiver
}
calleeReference = lhsGetCall.calleeReference
argumentList = buildArgumentList {
var i = 0
for (argument in lhsGetCall.argumentList.arguments) {
arguments += if (argument is FirVarargArgumentsExpression) {
buildVarargArgumentsExpression {
val varargSize = argument.arguments.size
arguments += indicesQualifiedAccessForGet.subList(i, i + varargSize)
i += varargSize
source = argument.source
coneTypeOrNull = argument.resolvedType
coneElementTypeOrNull = argument.coneElementTypeOrNull
}
} else {
indicesQualifiedAccessForGet[i++]
var i = 0
val newMapping = (lhsGetCall.argumentList as FirResolvedArgumentList).mapping.mapKeysTo(LinkedHashMap()) { (argument) ->
if (argument is FirVarargArgumentsExpression) {
buildVarargArgumentsExpression {
val varargSize = argument.arguments.size
arguments += indicesQualifiedAccessForGet.subList(i, i + varargSize)
i += varargSize
source = argument.source
coneTypeOrNull = argument.resolvedType
coneElementTypeOrNull = argument.coneElementTypeOrNull
}
} else {
indicesQualifiedAccessForGet[i++]
}
}
argumentList = buildResolvedArgumentList(
lhsGetCall.argumentList,
newMapping,
)
origin = FirFunctionCallOrigin.Operator
coneTypeOrNull = lhsGetCall.resolvedType
}