[FIR AA] Use resolvedType instead of coneTypeOrNull where applicable
#KT-61367 Fixed
This commit is contained in:
committed by
Space Team
parent
6d8091f0ff
commit
aebb3bf0ee
+2
-7
@@ -23,13 +23,7 @@ import org.jetbrains.kotlin.fir.declarations.resolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.resolved
|
||||
import org.jetbrains.kotlin.fir.declarations.toAnnotationClassId
|
||||
import org.jetbrains.kotlin.fir.declarations.toAnnotationClassIdSafe
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.arguments
|
||||
import org.jetbrains.kotlin.fir.expressions.calleeReference
|
||||
import org.jetbrains.kotlin.fir.expressions.unwrapAndFlattenArgument
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.plugin.CompilerRequiredAnnotationsHelper
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
@@ -51,6 +45,7 @@ internal fun mapAnnotationParameters(annotation: FirAnnotation): Map<Name, FirEx
|
||||
checkWithAttachment(annotation.resolved, { "By now the annotations argument mapping should have been resolved" }) {
|
||||
withFirEntry("annotation", annotation)
|
||||
withClassEntry("annotationTypeRef", annotation.annotationTypeRef)
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
withClassEntry("coneTypeOrNull", annotation.coneTypeOrNull)
|
||||
annotation.calleeReference?.let { withClassEntry("calleeReference", it) }
|
||||
}
|
||||
|
||||
+6
-2
@@ -415,7 +415,7 @@ internal class KtFirCallResolver(
|
||||
}
|
||||
|
||||
// Specially handle @ExtensionFunctionType
|
||||
if (dispatchReceiver?.coneTypeSafe<ConeKotlinType>()?.isExtensionFunctionType == true) {
|
||||
if (dispatchReceiver?.resolvedType?.isExtensionFunctionType == true) {
|
||||
firstArgIsExtensionReceiver = true
|
||||
}
|
||||
|
||||
@@ -923,7 +923,7 @@ internal class KtFirCallResolver(
|
||||
private fun FirArrayLiteral.toTypeArgumentsMapping(
|
||||
partiallyAppliedSymbol: KtPartiallyAppliedSymbol<*, *>
|
||||
): Map<KtTypeParameterSymbol, KtType> {
|
||||
val elementType = coneTypeSafe<ConeClassLikeType>()?.arrayElementType()?.asKtType() ?: return emptyMap()
|
||||
val elementType = resolvedType.arrayElementType()?.asKtType() ?: return emptyMap()
|
||||
val typeParameter = partiallyAppliedSymbol.symbol.typeParameters.singleOrNull() ?: return emptyMap()
|
||||
return mapOf(typeParameter to elementType)
|
||||
}
|
||||
@@ -1157,6 +1157,8 @@ internal class KtFirCallResolver(
|
||||
|
||||
private fun FirArrayLiteral.toKtCallInfo(): KtCallInfo? {
|
||||
val arrayOfSymbol = with(analysisSession) {
|
||||
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
val type = coneTypeSafe<ConeClassLikeType>()
|
||||
?: return run {
|
||||
val defaultArrayOfSymbol = arrayOfSymbol(arrayOf) ?: return null
|
||||
@@ -1202,6 +1204,8 @@ internal class KtFirCallResolver(
|
||||
val firSymbol = arrayOfSymbol.firSymbol
|
||||
// No type parameter means this is an arrayOf call of primitives, in which case there is no type arguments
|
||||
val typeParameter = firSymbol.fir.typeParameters.singleOrNull() ?: return KtSubstitutor.Empty(token)
|
||||
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
val elementType = coneTypeSafe<ConeClassLikeType>()?.arrayElementType() ?: return KtSubstitutor.Empty(token)
|
||||
val coneSubstitutor = substitutorByMap(mapOf(typeParameter.symbol to elementType), rootModuleSession)
|
||||
return firSymbolBuilder.typeBuilder.buildSubstitutor(coneSubstitutor)
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ internal class KtFirExpressionTypeProvider(
|
||||
// For unresolved `super`, we manually create an intersection type so that IDE features like completion can work correctly.
|
||||
val containingClass = (fir.dispatchReceiver as? FirThisReceiverExpression)?.calleeReference?.boundSymbol as? FirClassSymbol<*>
|
||||
|
||||
if (fir.calleeReference is FirSuperReference && fir.coneTypeOrNull is ConeErrorType && containingClass != null) {
|
||||
if (fir.calleeReference is FirSuperReference && fir.resolvedType is ConeErrorType && containingClass != null) {
|
||||
val superTypes = containingClass.resolvedSuperTypes
|
||||
when (superTypes.size) {
|
||||
0 -> analysisSession.builtinTypes.ANY
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.fir.types.isStableSmartcast
|
||||
import org.jetbrains.kotlin.fir.types.resolvedType
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis
|
||||
@@ -105,7 +106,7 @@ internal class KtFirSmartcastProvider(
|
||||
if (receiver == null || receiver == firExpression.explicitReceiver) return null
|
||||
if (!receiver.isStableSmartcast()) return null
|
||||
|
||||
val type = receiver.coneTypeSafe<ConeKotlinType>()?.asKtType() ?: return null
|
||||
val type = receiver.resolvedType.asKtType()
|
||||
return KtImplicitReceiverSmartCast(type, kind, token)
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -45,6 +45,8 @@ internal object FirAnnotationValueConverter {
|
||||
|
||||
private fun <T> FirConstExpression<T>.convertConstantExpression(): KtConstantAnnotationValue? {
|
||||
val expression = psi as? KtElement
|
||||
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
val type = coneTypeOrNull
|
||||
val constantValue = when {
|
||||
value == null -> KtConstantValue.KtNullConstantValue(expression)
|
||||
|
||||
+4
-4
@@ -178,19 +178,19 @@ internal object FirCompileTimeConstantEvaluator {
|
||||
|
||||
val opr1 = evaluate(functionCall.explicitReceiver, mode) ?: return null
|
||||
opr1.evaluate(function)?.let {
|
||||
return it.adjustType(functionCall.coneTypeOrNull)
|
||||
return it.adjustType(functionCall.resolvedType)
|
||||
}
|
||||
|
||||
val argument = functionCall.arguments.firstOrNull() ?: return null
|
||||
val opr2 = evaluate(argument, mode) ?: return null
|
||||
opr1.evaluate(function, opr2)?.let {
|
||||
return it.adjustType(functionCall.coneTypeOrNull)
|
||||
return it.adjustType(functionCall.resolvedType)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun FirConstExpression<*>.adjustType(expectedType: ConeKotlinType?): FirConstExpression<*> {
|
||||
val expectedKind = expectedType?.toConstantValueKind()
|
||||
private fun FirConstExpression<*>.adjustType(expectedType: ConeKotlinType): FirConstExpression<*> {
|
||||
val expectedKind = expectedType.toConstantValueKind()
|
||||
// Note that the resolved type for the const expression is not always matched with the const kind. For example,
|
||||
// fun foo(x: Int) {
|
||||
// when (x) {
|
||||
|
||||
+2
-2
@@ -422,7 +422,7 @@ internal object FirReferenceResolveHelper {
|
||||
// accessing the `super` property on `this`, hence this weird looking if condition. In addition, the current class type is available
|
||||
// from the dispatch receiver `this`.
|
||||
if (expression is KtLabelReferenceExpression && fir is FirPropertyAccessExpression && fir.calleeReference is FirSuperReference) {
|
||||
return listOfNotNull(fir.dispatchReceiver?.coneTypeOrNull?.toTargetSymbol(session, symbolBuilder))
|
||||
return listOfNotNull(fir.dispatchReceiver?.resolvedType?.toTargetSymbol(session, symbolBuilder))
|
||||
}
|
||||
val receiverOrImplicitInvoke = if (fir is FirImplicitInvokeCall) {
|
||||
fir.explicitReceiver?.unwrapSmartcastExpression()
|
||||
@@ -733,7 +733,7 @@ internal object FirReferenceResolveHelper {
|
||||
session: FirSession,
|
||||
symbolBuilder: KtSymbolByFirBuilder
|
||||
): Collection<KtSymbol> {
|
||||
val type = fir.coneTypeOrNull ?: return emptyList()
|
||||
val type = fir.resolvedType
|
||||
return listOfNotNull(type.toTargetSymbol(session, symbolBuilder))
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirArrayOfSymbolProvider.
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFirSafe
|
||||
import org.jetbrains.kotlin.fir.expressions.FirArrayLiteral
|
||||
import org.jetbrains.kotlin.fir.expressions.UnresolvedExpressionTypeAccess
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
|
||||
@@ -24,6 +25,8 @@ class KtFirCollectionLiteralReference(
|
||||
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
||||
check(this is KtFirAnalysisSession)
|
||||
val fir = element.getOrBuildFirSafe<FirArrayLiteral>(firResolveSession) ?: return emptyList()
|
||||
|
||||
@OptIn(UnresolvedExpressionTypeAccess::class)
|
||||
val type = fir.coneTypeSafe<ConeClassLikeType>() ?: return listOfNotNull(arrayOfSymbol(arrayOf))
|
||||
val call = arrayTypeToArrayOfCall[type.lookupTag.classId] ?: arrayOf
|
||||
return listOfNotNull(arrayOfSymbol(call))
|
||||
|
||||
Reference in New Issue
Block a user