[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
@@ -62,8 +62,7 @@ class IntegerLiteralAndOperatorApproximationTransformer(
constExpression: FirConstExpression<T>,
data: ConeKotlinType?,
): FirStatement {
@OptIn(UnresolvedExpressionTypeAccess::class)
val type = constExpression.coneTypeSafe<ConeIntegerLiteralType>() ?: return constExpression
val type = constExpression.resolvedType as? ConeIntegerLiteralType ?: return constExpression
val approximatedType = type.getApproximatedType(data?.fullyExpandedType(session))
constExpression.resultType = approximatedType
@Suppress("UNCHECKED_CAST")
@@ -79,8 +78,7 @@ class IntegerLiteralAndOperatorApproximationTransformer(
@Suppress("UnnecessaryVariable")
val call = integerLiteralOperatorCall
@OptIn(UnresolvedExpressionTypeAccess::class)
val operatorType = call.coneTypeSafe<ConeIntegerLiteralType>() ?: return call
val operatorType = call.resolvedType as? ConeIntegerLiteralType ?: return call
val approximatedType = operatorType.getApproximatedType(data?.fullyExpandedType(session))
call.transformDispatchReceiver(this, null)
call.transformExtensionReceiver(this, null)
@@ -37,7 +37,6 @@ import org.jetbrains.kotlin.fir.scopes.impl.isWrappedIntegerOperatorForUnsignedT
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImplWithoutSource
import org.jetbrains.kotlin.fir.visitors.FirDefaultTransformer
import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.visitors.TransformData
@@ -1291,8 +1290,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
.resolveDelegatingConstructorCall(delegatedConstructorCall, constructorType, containingClass.symbol.toLookupTag())
if (reference is FirThisReference && reference.boundSymbol == null) {
@OptIn(UnresolvedExpressionTypeAccess::class)
resolvedCall.dispatchReceiver?.coneTypeSafe<ConeClassLikeType>()?.lookupTag?.toSymbol(session)?.let {
(resolvedCall.dispatchReceiver?.resolvedType as? ConeClassLikeType)?.lookupTag?.toSymbol(session)?.let {
reference.replaceBoundSymbol(it)
}
}
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.*
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.fir.utils.exceptions.withFirEntry
import org.jetbrains.kotlin.fir.utils.exceptions.withFirSymbolEntry
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
@@ -180,8 +180,7 @@ class VariableStorageImpl(private val session: FirSession) : VariableStorage() {
property.modality != Modality.FINAL -> {
val dispatchReceiver = (originalFir.unwrapElement() as? FirQualifiedAccessExpression)?.dispatchReceiver ?: return null
@OptIn(UnresolvedExpressionTypeAccess::class)
val receiverType = dispatchReceiver.coneTypeSafe<ConeClassLikeType>()?.fullyExpandedType(session) ?: return null
val receiverType = (dispatchReceiver.resolvedType as? ConeClassLikeType)?.fullyExpandedType(session) ?: return null
val receiverSymbol = receiverType.lookupTag.toSymbol(session) ?: return null
when (val receiverFir = receiverSymbol.fir) {
is FirAnonymousObject -> PropertyStability.STABLE_VALUE
@@ -41,9 +41,6 @@ val FirExpression.resolvedType: ConeKotlinType
withFirEntry("expression", this@resolvedType)
}
@UnresolvedExpressionTypeAccess
inline fun <reified T : ConeKotlinType> FirExpression.coneTypeSafe(): T? = (coneTypeOrNull as? T)
@OptIn(UnresolvedExpressionTypeAccess::class)
val FirExpression.isResolved: Boolean get() = coneTypeOrNull != null