[NI] Place varargs at the end of value arguments list

This is needed to preserve behavior with the OI
This commit is contained in:
Mikhail Zarechenskiy
2020-04-27 03:08:00 +03:00
parent 639af69185
commit e3fe1bcf7c
3 changed files with 16 additions and 5 deletions
@@ -60,9 +60,11 @@ import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContextDeleg
import org.jetbrains.kotlin.types.typeUtil.contains
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
import org.jetbrains.kotlin.types.typeUtil.makeNullable
import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.addToStdlib.cast
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.util.*
import kotlin.collections.LinkedHashMap
class KotlinToResolvedCallTransformer(
private val callCheckers: Iterable<CallChecker>,
@@ -620,16 +622,21 @@ sealed class NewAbstractResolvedCall<D : CallableDescriptor>() : ResolvedCall<D>
private fun createValueArguments(): Map<ValueParameterDescriptor, ResolvedValueArgument> =
LinkedHashMap<ValueParameterDescriptor, ResolvedValueArgument>().also { result ->
var varargMappings: MutableList<Pair<ValueParameterDescriptor, VarargValueArgument>>? = null
for ((originalParameter, resolvedCallArgument) in argumentMappingByOriginal) {
val resultingParameter = resultingDescriptor.valueParameters[originalParameter.index]
result[resultingParameter] = when (resolvedCallArgument) {
ResolvedCallArgument.DefaultArgument ->
DefaultValueArgument.DEFAULT
is ResolvedCallArgument.SimpleArgument -> {
val valueArgument = resolvedCallArgument.callArgument.psiCallArgument.valueArgument
if (resultingParameter.isVararg)
VarargValueArgument().apply { addArgument(valueArgument) }
else
if (resultingParameter.isVararg) {
val vararg = VarargValueArgument().apply { addArgument(valueArgument) }
if (varargMappings == null) varargMappings = SmartList()
varargMappings.add(resultingParameter to vararg)
continue
} else
ExpressionValueArgument(valueArgument)
}
is ResolvedCallArgument.VarargArgument ->
@@ -638,6 +645,12 @@ sealed class NewAbstractResolvedCall<D : CallableDescriptor>() : ResolvedCall<D>
}
}
}
if (varargMappings != null) {
for ((parameter, argument) in varargMappings) {
result[parameter] = argument
}
}
}
}
@@ -1,4 +1,3 @@
// !LANGUAGE: -NewInference
// IGNORE_BACKEND: JS
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
@@ -1,4 +1,3 @@
// !LANGUAGE: -NewInference
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND: JS, JS_IR
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR