[FIR] Cleanup vararg handling during call completion
This commit is contained in:
+9
-10
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
|||||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import java.lang.Math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class FirCallCompletionResultsWriterTransformer(
|
class FirCallCompletionResultsWriterTransformer(
|
||||||
override val session: FirSession,
|
override val session: FirSession,
|
||||||
@@ -180,23 +180,22 @@ class FirCallCompletionResultsWriterTransformer(
|
|||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
resultType = typeRef.substituteTypeRef(subCandidate)
|
resultType = typeRef.substituteTypeRef(subCandidate)
|
||||||
val vararg = subCandidate.argumentMapping?.values?.firstOrNull { it.isVararg }
|
val argumentMapping = subCandidate.argumentMapping
|
||||||
|
val vararg = argumentMapping?.values?.firstOrNull { it.isVararg }
|
||||||
result.argumentList.transformArguments(this, subCandidate.createArgumentsMapping())
|
result.argumentList.transformArguments(this, subCandidate.createArgumentsMapping())
|
||||||
with(result.argumentList) call@{
|
with(result.argumentList) call@{
|
||||||
if (vararg != null) {
|
if (vararg != null) {
|
||||||
// Create a FirVarargArgumentExpression for the vararg arguments
|
// Create a FirVarargArgumentExpression for the vararg arguments
|
||||||
val resolvedArrayType = vararg.returnTypeRef.substitute(subCandidate)
|
val varargParameterTypeRef = vararg.returnTypeRef
|
||||||
|
val resolvedArrayType = varargParameterTypeRef.substitute(subCandidate)
|
||||||
val resolvedElementType = resolvedArrayType.arrayElementType(session)
|
val resolvedElementType = resolvedArrayType.arrayElementType(session)
|
||||||
var firstIndex = this@call.arguments.size
|
var firstIndex = this@call.arguments.size
|
||||||
val varargArgument = buildVarargArgumentsExpression {
|
val varargArgument = buildVarargArgumentsExpression {
|
||||||
varargElementType = vararg.returnTypeRef.withReplacedConeType(resolvedElementType)
|
varargElementType = varargParameterTypeRef.withReplacedConeType(resolvedElementType)
|
||||||
this.typeRef = vararg.returnTypeRef.withReplacedConeType(
|
this.typeRef = varargParameterTypeRef.withReplacedConeType(resolvedArrayType)
|
||||||
vararg.returnTypeRef.substitute(
|
|
||||||
subCandidate
|
|
||||||
)
|
|
||||||
)
|
|
||||||
for ((i, arg) in this@call.arguments.withIndex()) {
|
for ((i, arg) in this@call.arguments.withIndex()) {
|
||||||
if (subCandidate.argumentMapping!![arg]?.isVararg ?: false) {
|
val valueParameter = argumentMapping[arg] ?: continue
|
||||||
|
if (valueParameter.isVararg) {
|
||||||
firstIndex = min(firstIndex, i)
|
firstIndex = min(firstIndex, i)
|
||||||
arguments += arg
|
arguments += arg
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user