[FIR] Replace usages of FirExpression.typeRef with coneTypeOrNull

#KT-59855 Fixed
This commit is contained in:
Kirill Rakhman
2023-08-04 10:43:25 +02:00
committed by Space Team
parent f60d81097c
commit 8d7c5b375e
76 changed files with 538 additions and 565 deletions
@@ -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.typeRef is FirErrorTypeRef && containingClass != null) {
if (fir.calleeReference is FirSuperReference && fir.coneTypeOrNull is ConeErrorType && containingClass != null) {
val superTypes = containingClass.resolvedSuperTypes
when (superTypes.size) {
0 -> analysisSession.builtinTypes.ANY
@@ -214,9 +214,7 @@ internal class KtFirExpressionTypeProvider(
private fun getExpectedTypeByTypeCast(expression: PsiElement): KtType? {
val typeCastExpression =
expression.unwrapQualified<KtBinaryExpressionWithTypeRHS> { castExpr, expr -> castExpr.left == expr } ?: return null
with(analysisSession) {
return typeCastExpression.right?.getKtType()
}
return getKtExpressionType(typeCastExpression)
}
private fun getExpectedTypeOfFunctionParameter(expression: PsiElement): KtType? {
@@ -178,13 +178,13 @@ internal object FirCompileTimeConstantEvaluator {
val opr1 = evaluate(functionCall.explicitReceiver, mode) ?: return null
opr1.evaluate(function)?.let {
return it.adjustType(functionCall.type)
return it.adjustType(functionCall.coneTypeOrNull)
}
val argument = functionCall.arguments.firstOrNull() ?: return null
val opr2 = evaluate(argument, mode) ?: return null
opr1.evaluate(function, opr2)?.let {
return it.adjustType(functionCall.type)
return it.adjustType(functionCall.coneTypeOrNull)
}
return null
}
@@ -207,7 +207,7 @@ internal object FirCompileTimeConstantEvaluator {
}
// Lastly, we should preserve the resolved type of the original function call.
return expression.apply {
replaceType(expectedType)
replaceConeTypeOrNull(expectedType)
}
}
@@ -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.type?.toTargetSymbol(session, symbolBuilder))
return listOfNotNull(fir.dispatchReceiver.coneTypeOrNull?.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.type ?: return emptyList()
val type = fir.coneTypeOrNull ?: return emptyList()
return listOfNotNull(type.toTargetSymbol(session, symbolBuilder))
}