From 7ccf21c5c81d29b91de4dd67896e06e3ebc75d72 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 15 Jul 2019 18:39:10 +0300 Subject: [PATCH] FIR resolve: fix vararg parameter types --- .../fir/resolve/calls/OverloadConflictResolver.kt | 13 +++++++++++-- .../testData/resolve/stdlib/topLevelResolve.txt | 2 +- .../testData/ir/irText/stubs/builtinMap.fir.txt | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/OverloadConflictResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/OverloadConflictResolver.kt index 41fd2b946ff..ef91f6a147a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/OverloadConflictResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/OverloadConflictResolver.kt @@ -5,11 +5,14 @@ package org.jetbrains.kotlin.fir.resolve.calls +import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirConstructor import org.jetbrains.kotlin.fir.declarations.FirNamedFunction +import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.fir.types.ConeKotlinType +import org.jetbrains.kotlin.fir.types.arrayElementType import org.jetbrains.kotlin.fir.types.coneTypeUnsafe import org.jetbrains.kotlin.resolve.OverloadabilitySpecificityCallbacks import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl @@ -60,7 +63,7 @@ class ConeOverloadConflictResolver( return FlatSignature( call, constructor.typeParameters.map { it.symbol }, - call.argumentMapping!!.map { it.value.returnTypeRef.coneTypeUnsafe() }, + call.argumentMapping!!.map { it.value.argumentType() }, //constructor.receiverTypeRef != null, false, constructor.valueParameters.any { it.isVararg }, @@ -70,12 +73,18 @@ class ConeOverloadConflictResolver( ) } + private fun FirValueParameter.argumentType(): ConeKotlinType { + val type = returnTypeRef.coneTypeUnsafe() + if (isVararg) return type.arrayElementType(inferenceComponents.session)!! + return type + } + private fun createFlatSignature(call: Candidate, function: FirNamedFunction): FlatSignature { return FlatSignature( call, function.typeParameters.map { it.symbol }, listOfNotNull(function.receiverTypeRef?.coneTypeUnsafe()) + - call.argumentMapping!!.map { it.value.returnTypeRef.coneTypeUnsafe() }, + call.argumentMapping!!.map { it.value.argumentType() }, function.receiverTypeRef != null, function.valueParameters.any { it.isVararg }, function.valueParameters.count { it.defaultValue != null }, diff --git a/compiler/fir/resolve/testData/resolve/stdlib/topLevelResolve.txt b/compiler/fir/resolve/testData/resolve/stdlib/topLevelResolve.txt index 41b08c9b743..cdd09763226 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/topLevelResolve.txt +++ b/compiler/fir/resolve/testData/resolve/stdlib/topLevelResolve.txt @@ -13,7 +13,7 @@ FILE: topLevelResolve.kt lval setAndList: R|kotlin/collections/Set| = R|kotlin/collections/setOf|(Int(0)).R|kotlin/collections/plus|(R|kotlin/collections/listOf|(Int(1), Int(2))) lval stringAndList: R|kotlin/String| = String().R|kotlin/String.plus|(R|kotlin/collections/emptyList|()) lval map: R|kotlin/collections/Map| = R|kotlin/collections/mapOf|(String().R|kotlin/to|(Int(1)), String(.).R|kotlin/to|(Int(2))).R|kotlin/collections/plus|(String(..).R|kotlin/to|(Int(3))) - lval mapAndMap: = #(String(-).R?C|kotlin/to|(Int(4))).#(#(String(_).R?C|kotlin/to|(Int(5)))) + lval mapAndMap: R|kotlin/collections/Map| = R|kotlin/collections/mapOf|(String(-).R|kotlin/to|(Int(4))).R|kotlin/collections/plus|(R|kotlin/collections/mapOf|(String(_).R|kotlin/to|(Int(5)))) } public final fun id(arg: R|T|): R|T| { ^id R|/arg| diff --git a/compiler/testData/ir/irText/stubs/builtinMap.fir.txt b/compiler/testData/ir/irText/stubs/builtinMap.fir.txt index 3226507838f..263acc3c20b 100644 --- a/compiler/testData/ir/irText/stubs/builtinMap.fir.txt +++ b/compiler/testData/ir/irText/stubs/builtinMap.fir.txt @@ -9,8 +9,8 @@ FILE fqName: fileName:/builtinMap.kt BRANCH if: CALL 'public abstract fun isEmpty (): kotlin.Boolean declared in kotlin.collections.Map' type=kotlin.Boolean origin=null $this: ERROR_CALL 'Unresolved reference: this#' type=kotlin.collections.Map.plus, V1 of .plus> - then: ERROR_CALL 'Unresolved reference: #' type=IrErrorType - GET_VAR 'pair: kotlin.Pair.plus, V1 of .plus> declared in .plus' type=kotlin.Pair.plus, V1 of .plus> origin=null + then: CALL 'public final fun mapOf (pair: kotlin.Pair, V of >): kotlin.collections.Map, V of > declared in kotlin.collections' type=kotlin.collections.Map.plus, V1 of .plus> origin=null + pair: GET_VAR 'pair: kotlin.Pair.plus, V1 of .plus> declared in .plus' type=kotlin.Pair.plus, V1 of .plus> origin=null BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CALL 'public final fun apply (block: kotlin.Function1, kotlin.Unit>): T of [inline] declared in kotlin' type=java.util.LinkedHashMap.plus, V1 of .plus> origin=null