[FIR] Use ConeKotlinType to represent vararg's element type
We are using `ConeKotlinType` instead of `FirTypeRef` to represent that element type of vararg doesn't have any source. It has a type that was inferred. If we try to specify a source, then we could end up with the incorrect place for diagnostic. #KT-59682 Fixed
This commit is contained in:
+3
-4
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fakeElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.copyWithNewSource
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
|
||||
@@ -38,15 +39,13 @@ internal fun remapArgumentsWithVararg(
|
||||
// Create a FirVarargArgumentExpression for the vararg arguments.
|
||||
// The order of arguments in the mapping must be preserved for FIR2IR, hence we have to find where the vararg arguments end.
|
||||
// FIR2IR uses the mapping order to determine if arguments need to be reordered.
|
||||
val varargParameterTypeRef = varargParameter.returnTypeRef
|
||||
val varargElementType = varargArrayType.arrayElementType()?.approximateIntegerLiteralType()
|
||||
val argumentList = argumentMapping.keys.toList()
|
||||
var indexAfterVarargs = argumentList.size
|
||||
val newArgumentMapping = linkedMapOf<FirExpression, FirValueParameter>()
|
||||
val varargArgument = buildVarargArgumentsExpression {
|
||||
// TODO: ideally we should use here a source from the use-site and not from the declaration-site, KT-59682
|
||||
this.varargElementType = varargParameterTypeRef.withReplacedConeType(varargElementType, KtFakeSourceElementKind.VarargArgument)
|
||||
this.coneTypeOrNull = varargArrayType
|
||||
coneElementTypeOrNull = varargElementType
|
||||
coneTypeOrNull = varargArrayType
|
||||
var startOffset = Int.MAX_VALUE
|
||||
var endOffset = 0
|
||||
var firstVarargElementSource: KtSourceElement? = null
|
||||
|
||||
+1
-1
@@ -1600,7 +1600,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
i += varargSize
|
||||
source = argument.source
|
||||
coneTypeOrNull = argument.resolvedType
|
||||
varargElementType = argument.varargElementType
|
||||
coneElementTypeOrNull = argument.coneElementTypeOrNull
|
||||
}
|
||||
} else {
|
||||
indicesQualifiedAccessForGet[i++]
|
||||
|
||||
Reference in New Issue
Block a user