[FIR] Inline FirExpression.coneTypeSafe und use resolvedType

The call-sites don't actually need to handle unresolved expressions,
they only need safe-casts to ConeClassLikeType or
ConeIntegerLiteralType.

#KT-61367
This commit is contained in:
Kirill Rakhman
2023-09-12 17:36:20 +02:00
committed by Space Team
parent a4fff7c7c0
commit 0d628c9e59
6 changed files with 9 additions and 21 deletions
@@ -1158,8 +1158,7 @@ internal class KtFirCallResolver(
private fun FirArrayLiteral.toKtCallInfo(): KtCallInfo? {
val arrayOfSymbol = with(analysisSession) {
@OptIn(UnresolvedExpressionTypeAccess::class)
val type = coneTypeSafe<ConeClassLikeType>()
val type = resolvedType as? ConeClassLikeType
?: return run {
val defaultArrayOfSymbol = arrayOfSymbol(arrayOf) ?: return null
val substitutor = createSubstitutorFromTypeArguments(defaultArrayOfSymbol)
@@ -1205,8 +1204,7 @@ internal class KtFirCallResolver(
// 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 elementType = resolvedType.arrayElementType() ?: return KtSubstitutor.Empty(token)
val coneSubstitutor = substitutorByMap(mapOf(typeParameter.symbol to elementType), rootModuleSession)
return firSymbolBuilder.typeBuilder.buildSubstitutor(coneSubstitutor)
}
@@ -13,9 +13,8 @@ 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
import org.jetbrains.kotlin.fir.types.resolvedType
import org.jetbrains.kotlin.psi.KtCollectionLiteralExpression
@@ -26,8 +25,7 @@ class KtFirCollectionLiteralReference(
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 type = fir.resolvedType as? ConeClassLikeType ?: return listOfNotNull(arrayOfSymbol(arrayOf))
val call = arrayTypeToArrayOfCall[type.lookupTag.classId] ?: arrayOf
return listOfNotNull(arrayOfSymbol(call))
}