[FIR] Replace FirExpression.typeRef.coneType (and variants) with FirExpression.coneType

#KT-59855
This commit is contained in:
Kirill Rakhman
2023-07-31 17:36:01 +02:00
committed by Space Team
parent 1472b21993
commit 9ec814b7ad
108 changed files with 289 additions and 299 deletions
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.fir.declarations.resolvePhase
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.expressions.unwrapAndFlattenArgument
import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol
import org.jetbrains.kotlin.fir.types.coneTypeOrNull
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
@@ -50,7 +51,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)
withClassEntry("typeRef", annotation.typeRef)
withClassEntry("coneTypeOrNull", annotation.coneTypeOrNull)
}
return annotation.argumentMapping.mapping.mapKeys { (name, _) -> name }
@@ -215,4 +216,4 @@ internal fun hasAnnotation(
}
private fun FirBasedSymbol<*>.isFromCompilerRequiredAnnotationsPhase(classId: ClassId): Boolean =
fir.resolvePhase < FirResolvePhase.TYPES && classId in CompilerRequiredAnnotationsHelper.REQUIRED_ANNOTATIONS
fir.resolvePhase < FirResolvePhase.TYPES && classId in CompilerRequiredAnnotationsHelper.REQUIRED_ANNOTATIONS
@@ -413,7 +413,7 @@ internal class KtFirCallResolver(
}
// Specially handle @ExtensionFunctionType
if (dispatchReceiver.typeRef.coneTypeSafe<ConeKotlinType>()?.isExtensionFunctionType == true) {
if (dispatchReceiver.coneTypeSafe<ConeKotlinType>()?.isExtensionFunctionType == true) {
firstArgIsExtensionReceiver = true
}
@@ -421,7 +421,7 @@ internal class KtFirCallResolver(
val extensionReceiverValue: KtReceiverValue?
if (explicitReceiverKind == ExplicitReceiverKind.DISPATCH_RECEIVER) {
dispatchReceiverValue =
KtExplicitReceiverValue(explicitReceiverPsi, dispatchReceiver.typeRef.coneType.asKtType(), false, token)
KtExplicitReceiverValue(explicitReceiverPsi, dispatchReceiver.coneType.asKtType(), false, token)
if (firstArgIsExtensionReceiver) {
extensionReceiverValue = (fir as FirFunctionCall).arguments.firstOrNull()?.toKtReceiverValue()
} else {
@@ -430,7 +430,7 @@ internal class KtFirCallResolver(
} else {
dispatchReceiverValue = dispatchReceiver.toKtReceiverValue()
extensionReceiverValue =
KtExplicitReceiverValue(explicitReceiverPsi, extensionReceiver.typeRef.coneType.asKtType(), false, token)
KtExplicitReceiverValue(explicitReceiverPsi, extensionReceiver.coneType.asKtType(), false, token)
}
return KtPartiallyAppliedSymbol(
with(analysisSession) { unsubstitutedKtSignature.substitute(substitutor) },
@@ -777,12 +777,12 @@ internal class KtFirCallResolver(
(calleeReference as? FirResolvedNamedReference)?.resolvedSymbol as? FirNamedFunctionSymbol ?: return null
val substitutor = createConeSubstitutorFromTypeArguments() ?: return null
val dispatchReceiverValue = if (explicitReceiverPsiSupplement != null && explicitReceiver == dispatchReceiver) {
explicitReceiverPsiSupplement.toExplicitReceiverValue(dispatchReceiver.typeRef.coneType.asKtType())
explicitReceiverPsiSupplement.toExplicitReceiverValue(dispatchReceiver.coneType.asKtType())
} else {
dispatchReceiver.toKtReceiverValue()
}
val extensionReceiverValue = if (explicitReceiverPsiSupplement != null && explicitReceiver == extensionReceiver) {
explicitReceiverPsiSupplement.toExplicitReceiverValue(extensionReceiver.typeRef.coneType.asKtType())
explicitReceiverPsiSupplement.toExplicitReceiverValue(extensionReceiver.coneType.asKtType())
} else {
extensionReceiver.toKtReceiverValue()
}
@@ -811,12 +811,12 @@ internal class KtFirCallResolver(
?: return null
else -> return null
}
KtImplicitReceiverValue(implicitPartiallyAppliedSymbol, typeRef.coneType.asKtType())
KtImplicitReceiverValue(implicitPartiallyAppliedSymbol, coneType.asKtType())
}
else -> {
val psi = psi
if (psi !is KtExpression) return null
psi.toExplicitReceiverValue(typeRef.coneType.asKtType())
psi.toExplicitReceiverValue(coneType.asKtType())
}
}
}
@@ -875,7 +875,7 @@ internal class KtFirCallResolver(
private fun FirArrayLiteral.toTypeArgumentsMapping(
partiallyAppliedSymbol: KtPartiallyAppliedSymbol<*, *>
): Map<KtTypeParameterSymbol, KtType> {
val elementType = typeRef.coneTypeSafe<ConeClassLikeType>()?.arrayElementType()?.asKtType() ?: return emptyMap()
val elementType = coneTypeSafe<ConeClassLikeType>()?.arrayElementType()?.asKtType() ?: return emptyMap()
val typeParameter = partiallyAppliedSymbol.symbol.typeParameters.singleOrNull() ?: return emptyMap()
return mapOf(typeParameter to elementType)
}
@@ -1109,7 +1109,7 @@ internal class KtFirCallResolver(
private fun FirArrayLiteral.toKtCallInfo(): KtCallInfo? {
val arrayOfSymbol = with(analysisSession) {
val type = typeRef.coneTypeSafe<ConeClassLikeType>()
val type = coneTypeSafe<ConeClassLikeType>()
?: return run {
val defaultArrayOfSymbol = arrayOfSymbol(arrayOf) ?: return null
val substitutor = createSubstitutorFromTypeArguments(defaultArrayOfSymbol)
@@ -1154,7 +1154,7 @@ 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)
val elementType = typeRef.coneTypeSafe<ConeClassLikeType>()?.arrayElementType() ?: return KtSubstitutor.Empty(token)
val elementType = coneTypeSafe<ConeClassLikeType>()?.arrayElementType() ?: return KtSubstitutor.Empty(token)
val coneSubstitutor = substitutorByMap(mapOf(typeParameter.symbol to elementType), rootModuleSession)
return firSymbolBuilder.typeBuilder.buildSubstitutor(coneSubstitutor)
}
@@ -1169,7 +1169,7 @@ internal class KtFirCallResolver(
val equalsSymbolInAny = equalsSymbolInAny
val leftOperand = arguments.firstOrNull() ?: return null
val session = analysisSession.useSiteSession
val leftOperandType = leftOperand.typeRef.coneType
val leftOperandType = leftOperand.coneType
val classSymbol = leftOperandType.fullyExpandedType(session).toSymbol(session) as? FirClassSymbol<*>
val equalsSymbol = classSymbol?.getEqualsSymbol(equalsSymbolInAny) ?: equalsSymbolInAny
@@ -67,7 +67,7 @@ internal class KtFirExpressionTypeProvider(
}
private fun getKtExpressionType(expression: KtExpression, fir: FirElement): KtType? = when (fir) {
is FirFunctionCall -> getReturnTypeForArrayStyleAssignmentTarget(expression, fir) ?: fir.typeRef.coneType.asKtType()
is FirFunctionCall -> getReturnTypeForArrayStyleAssignmentTarget(expression, fir) ?: fir.coneType.asKtType()
is FirPropertyAccessExpression -> {
// 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<*>
@@ -80,19 +80,19 @@ internal class KtFirExpressionTypeProvider(
else -> ConeIntersectionType(superTypes).asKtType()
}
} else {
fir.typeRef.coneType.asKtType()
fir.coneType.asKtType()
}
}
is FirVariableAssignment -> {
if (fir.lValue.source?.psi == expression) {
fir.lValue.typeRef.coneType.asKtType()
fir.lValue.coneType.asKtType()
} else if (expression is KtUnaryExpression && expression.operationToken in KtTokens.INCREMENT_AND_DECREMENT) {
fir.rValue.typeRef.coneType.asKtType()
fir.rValue.coneType.asKtType()
} else {
analysisSession.builtinTypes.UNIT
}
}
is FirExpression -> fir.typeRef.coneType.asKtType()
is FirExpression -> fir.coneType.asKtType()
is FirNamedReference -> fir.getCorrespondingTypeIfPossible()?.asKtType()
is FirStatement -> with(analysisSession) { builtinTypes.UNIT }
is FirTypeRef, is FirImport, is FirPackageDirective, is FirLabel, is FirTypeParameterRef -> null
@@ -123,7 +123,7 @@ internal class KtFirExpressionTypeProvider(
* of the whole expression instead, and that is not what he wants.
*/
private fun FirNamedReference.getCorrespondingTypeIfPossible(): ConeKotlinType? =
findOuterPropertyAccessExpression()?.typeRef?.coneType
findOuterPropertyAccessExpression()?.coneType
/**
* Finds an outer expression for [this] named reference in cases when it is a part of a property access.
@@ -427,7 +427,7 @@ internal class KtFirExpressionTypeProvider(
private fun getDefiniteNullability(expression: KtExpression): DefiniteNullability {
fun FirExpression.isNotNullable() = with(analysisSession.useSiteSession.typeContext) {
!typeRef.coneType.isNullableType()
!coneType.isNullableType()
}
when (val fir = expression.getOrBuildFir(analysisSession.firResolveSession)) {
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.element.builder.FirTowerC
import org.jetbrains.kotlin.analysis.low.level.api.fir.resolver.AllCandidatesResolver
import org.jetbrains.kotlin.analysis.utils.printer.parentsOfType
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.builder.buildImport
import org.jetbrains.kotlin.fir.declarations.builder.buildResolvedImport
@@ -326,8 +325,8 @@ private class FirShorteningContext(val analysisSession: KtFirAnalysisSession) {
}
}
fun getRegularClass(typeRef: FirTypeRef): FirRegularClass? {
return typeRef.toRegularClassSymbol(firSession)?.fir
fun getRegularClass(type: ConeKotlinType?): FirRegularClass? {
return type?.toRegularClassSymbol(firSession)?.fir
}
fun toClassSymbol(classId: ClassId) =
@@ -1314,4 +1313,4 @@ private fun KtElement.getQualifier(): KtElement? = when (this) {
is KtUserType -> qualifier
is KtDotQualifiedExpression -> receiverExpression
else -> null
}
}
@@ -105,7 +105,7 @@ internal class KtFirSmartcastProvider(
if (receiver == firExpression.explicitReceiver) return null
if (!receiver.isStableSmartcast()) return null
val type = receiver.typeRef.coneTypeSafe<ConeKotlinType>()?.asKtType() ?: return null
val type = receiver.coneTypeSafe<ConeKotlinType>()?.asKtType() ?: return null
return KtImplicitReceiverSmartCast(type, kind, token)
}
}
@@ -172,9 +172,9 @@ internal class KtFirTypeProvider(
override fun getReceiverTypeForDoubleColonExpression(expression: KtDoubleColonExpression): KtType? {
return when (val fir = expression.getOrBuildFir(firResolveSession)) {
is FirGetClassCall ->
fir.typeRef.coneType.getReceiverOfReflectionType()?.asKtType()
fir.coneType.getReceiverOfReflectionType()?.asKtType()
is FirCallableReferenceAccess ->
fir.typeRef.coneType.getReceiverOfReflectionType()?.asKtType()
fir.coneType.getReceiverOfReflectionType()?.asKtType()
else -> throwUnexpectedFirElementError(fir, expression)
}
}
@@ -45,7 +45,7 @@ internal object FirAnnotationValueConverter {
private fun <T> FirConstExpression<T>.convertConstantExpression(): KtConstantAnnotationValue? {
val expression = psi as? KtElement
val type = (typeRef as? FirResolvedTypeRef)?.type
val type = coneTypeOrNull
val constantValue = when {
value == null -> KtConstantValue.KtNullConstantValue(expression)
type == null -> KtConstantValueFactory.createConstantValue(value, psi as? KtElement)
@@ -179,7 +179,7 @@ internal object FirAnnotationValueConverter {
val qualifierParts = mutableListOf<String?>()
fun process(expression: FirExpression) {
val errorType = expression.typeRef.coneType as? ConeErrorType
val errorType = expression.coneType as? ConeErrorType
val unresolvedName = when (val diagnostic = errorType?.diagnostic) {
is ConeUnresolvedTypeQualifierError -> diagnostic.qualifier
is ConeUnresolvedNameError -> diagnostic.qualifier
@@ -178,19 +178,19 @@ internal object FirCompileTimeConstantEvaluator {
val opr1 = evaluate(functionCall.explicitReceiver, mode) ?: return null
opr1.evaluate(function)?.let {
return it.adjustType(functionCall.typeRef)
return it.adjustType(functionCall.type)
}
val argument = functionCall.arguments.firstOrNull() ?: return null
val opr2 = evaluate(argument, mode) ?: return null
opr1.evaluate(function, opr2)?.let {
return it.adjustType(functionCall.typeRef)
return it.adjustType(functionCall.type)
}
return null
}
private fun FirConstExpression<*>.adjustType(expectedType: FirTypeRef): 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) {
@@ -207,7 +207,7 @@ internal object FirCompileTimeConstantEvaluator {
}
// Lastly, we should preserve the resolved type of the original function call.
return expression.apply {
replaceTypeRef(expectedType)
replaceType(expectedType)
}
}
@@ -304,25 +304,6 @@ internal object FirCompileTimeConstantEvaluator {
////// KINDS
private fun FirTypeRef.toConstantValueKind(): ConstantValueKind<*>? =
when (this) {
!is FirResolvedTypeRef -> null
!is FirImplicitBuiltinTypeRef -> type.toConstantValueKind()
is FirImplicitByteTypeRef -> ConstantValueKind.Byte
is FirImplicitDoubleTypeRef -> ConstantValueKind.Double
is FirImplicitFloatTypeRef -> ConstantValueKind.Float
is FirImplicitIntTypeRef -> ConstantValueKind.Int
is FirImplicitLongTypeRef -> ConstantValueKind.Long
is FirImplicitShortTypeRef -> ConstantValueKind.Short
is FirImplicitCharTypeRef -> ConstantValueKind.Char
is FirImplicitStringTypeRef -> ConstantValueKind.String
is FirImplicitBooleanTypeRef -> ConstantValueKind.Boolean
else -> null
}
private fun ConeKotlinType.toConstantValueKind(): ConstantValueKind<*>? =
when (this) {
is ConeErrorType -> null
@@ -58,12 +58,20 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
internal object FirReferenceResolveHelper {
fun FirResolvedTypeRef.toTargetSymbol(session: FirSession, symbolBuilder: KtSymbolByFirBuilder): KtSymbol? {
val type = getDeclaredType() as? ConeLookupTagBasedType
return type?.toTargetSymbol(session, symbolBuilder) ?: run {
val diagnostic = (this as? FirErrorTypeRef)?.diagnostic
(diagnostic as? ConeUnmatchedTypeArgumentsError)?.symbol?.fir?.buildSymbol(symbolBuilder)
}
}
private fun ConeKotlinType.toTargetSymbol(session: FirSession, symbolBuilder: KtSymbolByFirBuilder): KtSymbol? {
val type = this as? ConeLookupTagBasedType
val resolvedSymbol = type?.lookupTag?.toSymbol(session) as? FirBasedSymbol<*>
val symbol = resolvedSymbol ?: run {
val diagnostic = (this as? FirErrorTypeRef)?.diagnostic
val diagnostic = (this as? ConeErrorType)?.diagnostic
(diagnostic as? ConeUnmatchedTypeArgumentsError)?.symbol
}
@@ -253,7 +261,7 @@ internal object FirReferenceResolveHelper {
symbolBuilder: KtSymbolByFirBuilder
): Collection<KtSymbol> {
val lhs = expression.arguments.firstOrNull() ?: return emptyList()
val scope = lhs.typeRef.coneType.scope(
val scope = lhs.coneType.scope(
session,
analysisSession.getScopeSessionFor(analysisSession.useSiteSession),
FakeOverrideTypeCalculator.DoNothing,
@@ -414,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.typeRef as? FirResolvedTypeRef)?.toTargetSymbol(session, symbolBuilder))
return listOfNotNull(fir.dispatchReceiver.type?.toTargetSymbol(session, symbolBuilder))
}
val receiverOrImplicitInvoke = if (fir is FirImplicitInvokeCall) {
fir.explicitReceiver?.unwrapSmartcastExpression()
@@ -725,7 +733,7 @@ internal object FirReferenceResolveHelper {
session: FirSession,
symbolBuilder: KtSymbolByFirBuilder
): Collection<KtSymbol> {
val type = fir.typeRef as? FirResolvedTypeRef ?: return emptyList()
val type = fir.type ?: return emptyList()
return listOfNotNull(type.toTargetSymbol(session, symbolBuilder))
}
@@ -24,7 +24,7 @@ class KtFirCollectionLiteralReference(
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
check(this is KtFirAnalysisSession)
val fir = element.getOrBuildFirSafe<FirArrayLiteral>(firResolveSession) ?: return emptyList()
val type = fir.typeRef.coneTypeSafe<ConeClassLikeType>() ?: return listOfNotNull(arrayOfSymbol(arrayOf))
val type = fir.coneTypeSafe<ConeClassLikeType>() ?: return listOfNotNull(arrayOfSymbol(arrayOf))
val call = arrayTypeToArrayOfCall[type.lookupTag.classId] ?: arrayOf
return listOfNotNull(arrayOfSymbol(call))
}
@@ -27,7 +27,7 @@ object FirJsDynamicDeclarationChecker : FirClassChecker() {
// and it's a shape it couldn't have been accessed directly
val initializer = delegate.fir.initializer ?: continue
if (initializer.typeRef.coneType is ConeDynamicType) {
if (initializer.coneType is ConeDynamicType) {
reporter.reportOn(initializer.source, FirJsErrors.DELEGATION_BY_DYNAMIC, context)
}
}
@@ -34,9 +34,9 @@ object FirJsExternalFileChecker : FirBasicDeclarationChecker() {
reporter.reportOn(
declaration.source,
FirJsErrors.NON_EXTERNAL_DECLARATION_IN_INAPPROPRIATE_FILE,
targetAnnotations.typeRef.coneType,
targetAnnotations.coneType,
context
)
}
}
}
}
@@ -36,7 +36,7 @@ internal abstract class FirJsAbstractNativeAnnotationChecker(private val require
reporter.reportOn(
declaration.source,
FirJsErrors.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN,
annotation.typeRef.coneType,
annotation.coneType,
context
)
}
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.types.coneTypeOrNull
object FirJsPropertyDelegationByDynamicChecker : FirPropertyChecker() {
override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) {
if (declaration.delegate?.typeRef?.coneTypeOrNull is ConeDynamicType) {
if (declaration.delegate?.coneTypeOrNull is ConeDynamicType) {
reporter.reportOn(declaration.delegate?.source, FirJsErrors.PROPERTY_DELEGATION_BY_DYNAMIC, context)
}
}
@@ -90,7 +90,7 @@ object FirJsDynamicCallChecker : FirQualifiedAccessExpressionChecker() {
private fun checkSpreadOperator(expression: FirQualifiedAccessExpression, context: CheckerContext, reporter: DiagnosticReporter) {
forAllSpreadArgumentsOf(expression) {
if (it.typeRef.coneType is ConeDynamicType) {
if (it.coneType is ConeDynamicType) {
reporter.reportOn(it.source, FirJsErrors.WRONG_OPERATION_WITH_DYNAMIC, "spread operator", context)
}
}
@@ -26,7 +26,7 @@ object FirJsExternalArgumentCallChecker : FirCallChecker() {
for ((argument, parameter) in arguments) {
if (parameter.hasAnnotation(JsExternalArgument, context.session)) {
val unwrappedArg = argument.unwrapArgument()
val type = unwrappedArg.typeRef.coneTypeOrNull ?: continue
val type = unwrappedArg.coneTypeOrNull ?: continue
val symbol = type.toRegularClassSymbol(context.session)
if (symbol?.isEffectivelyExternal(context.session) == false || type is ConeDynamicType) {
reporter.reportOn(
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.types.toSymbol
object FirJsModuleGetClassCallChecker : FirGetClassCallChecker() {
override fun check(expression: FirGetClassCall, context: CheckerContext, reporter: DiagnosticReporter) {
val callee = expression.argument.typeRef.coneTypeOrNull?.toSymbol(context.session) ?: return
val callee = expression.argument.coneTypeOrNull?.toSymbol(context.session) ?: return
checkJsModuleUsage(callee, context, reporter, expression.argument.typeRef.source ?: expression.source)
}
}
@@ -7,13 +7,14 @@ package org.jetbrains.kotlin.fir.analysis.js.checkers.expression
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.analysis.checkers.*
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirBasicExpressionChecker
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
import org.jetbrains.kotlin.fir.analysis.diagnostics.js.FirJsErrors
import org.jetbrains.kotlin.fir.analysis.js.checkers.isNativeInterface
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
object FirJsNativeRttiChecker : FirBasicExpressionChecker() {
override fun check(expression: FirStatement, context: CheckerContext, reporter: DiagnosticReporter) {
@@ -25,7 +26,7 @@ object FirJsNativeRttiChecker : FirBasicExpressionChecker() {
}
private fun checkGetClassCall(expression: FirGetClassCall, context: CheckerContext, reporter: DiagnosticReporter) {
val declarationToCheck = expression.argument.typeRef.toRegularClassSymbol(context.session) ?: return
val declarationToCheck = expression.argument.coneType.toRegularClassSymbol(context.session) ?: return
if (expression.arguments.firstOrNull() !is FirResolvedQualifier) {
return
@@ -48,7 +49,7 @@ object FirJsNativeRttiChecker : FirBasicExpressionChecker() {
FirOperation.AS, FirOperation.SAFE_AS -> reporter.reportOn(
expression.source,
FirJsErrors.UNCHECKED_CAST_TO_EXTERNAL_INTERFACE,
expression.argument.typeRef.coneType,
expression.argument.coneType,
targetTypeRef.coneType,
context,
)
@@ -61,4 +62,4 @@ object FirJsNativeRttiChecker : FirBasicExpressionChecker() {
else -> {}
}
}
}
}
@@ -28,7 +28,7 @@ object FirJvmNameChecker : FirBasicDeclarationChecker() {
val jvmName = declaration.findJvmNameAnnotation() ?: return
val name = jvmName.findArgumentByName(StandardNames.NAME) ?: return
if (name.typeRef.coneType != context.session.builtinTypes.stringType.type) {
if (name.coneType != context.session.builtinTypes.stringType.type) {
return
}
@@ -70,7 +70,7 @@ object FirJavaGenericVarianceViolationTypeChecker : FirFunctionCallChecker() {
// Anything is acceptable for raw types
if (expectedType is ConeRawType) continue
val argType = arg.typeRef.coneType
val argType = arg.coneType
val lowerBound = expectedType.lowerBound
val upperBound = expectedType.upperBound
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.context.findClosest
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirBasicExpressionChecker
import org.jetbrains.kotlin.fir.analysis.checkers.getContainingDeclarationSymbol
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.getAnnotationByClassId
@@ -24,6 +23,8 @@ import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol
import org.jetbrains.kotlin.fir.resolve.defaultType
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
import org.jetbrains.kotlin.fir.types.typeContext
import org.jetbrains.kotlin.resolve.annotations.JVM_STATIC_ANNOTATION_CLASS_ID
import org.jetbrains.kotlin.types.AbstractTypeChecker
@@ -37,7 +38,7 @@ object FirJvmProtectedInSuperClassCompanionCallChecker : FirBasicExpressionCheck
} ?: return
if (dispatchReceiver is FirNoReceiverExpression) return
val dispatchClassSymbol = dispatchReceiver.typeRef.toRegularClassSymbol(context.session) ?: return
val dispatchClassSymbol = dispatchReceiver.coneType.toRegularClassSymbol(context.session) ?: return
val calleeReference = expression.calleeReference
val resolvedSymbol = calleeReference?.toResolvedCallableSymbol() ?: return
@@ -7,16 +7,18 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirGetClassCallChecker
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
import org.jetbrains.kotlin.fir.analysis.diagnostics.native.FirNativeErrors
import org.jetbrains.kotlin.fir.analysis.native.checkers.forwardDeclarationKindOrNull
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier
import org.jetbrains.kotlin.fir.expressions.arguments
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
object FirNativeForwardDeclarationGetClassCallChecker : FirGetClassCallChecker() {
override fun check(expression: FirGetClassCall, context: CheckerContext, reporter: DiagnosticReporter) {
val declarationToCheck = expression.argument.typeRef.toRegularClassSymbol(context.session) ?: return
val declarationToCheck = expression.argument.coneType.toRegularClassSymbol(context.session) ?: return
if (expression.arguments.firstOrNull() !is FirResolvedQualifier) {
return
@@ -26,9 +28,9 @@ object FirNativeForwardDeclarationGetClassCallChecker : FirGetClassCallChecker()
reporter.reportOn(
expression.source,
FirNativeErrors.FORWARD_DECLARATION_AS_CLASS_LITERAL,
expression.argument.typeRef.coneType,
expression.argument.coneType,
context,
)
}
}
}
}
@@ -7,14 +7,17 @@ package org.jetbrains.kotlin.fir.analysis.native.checkers
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.analysis.checkers.*
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirTypeOperatorCallChecker
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
import org.jetbrains.kotlin.fir.analysis.diagnostics.native.FirNativeErrors
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.FirOperation
import org.jetbrains.kotlin.fir.expressions.FirTypeOperatorCall
import org.jetbrains.kotlin.fir.expressions.argument
import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes
import org.jetbrains.kotlin.fir.types.classId
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
object FirNativeForwardDeclarationTypeOperatorChecker : FirTypeOperatorCallChecker() {
override fun check(expression: FirTypeOperatorCall, context: CheckerContext, reporter: DiagnosticReporter) {
@@ -24,8 +27,7 @@ object FirNativeForwardDeclarationTypeOperatorChecker : FirTypeOperatorCallCheck
when (expression.operation) {
FirOperation.AS, FirOperation.SAFE_AS -> {
val sourceTypeRef = expression.argument.typeRef
val sourceClass = sourceTypeRef.toRegularClassSymbol(context.session)
val sourceClass = expression.argument.coneType.toRegularClassSymbol(context.session)
// It can make sense to avoid warning if sourceClass is subclass of class with such property,
// but for the sake of simplicity, we don't do it now.
if (sourceClass != null && sourceClass.classKind == fwdKind.classKind && sourceClass.name == declarationToCheck.name) {
@@ -42,8 +44,8 @@ object FirNativeForwardDeclarationTypeOperatorChecker : FirTypeOperatorCallCheck
reporter.reportOn(
expression.source,
FirNativeErrors.UNCHECKED_CAST_TO_FORWARD_DECLARATION,
expression.argument.typeRef.coneType,
sourceTypeRef.coneType,
expression.argument.coneType,
expression.argument.coneType,
context,
)
}
@@ -56,4 +58,4 @@ object FirNativeForwardDeclarationTypeOperatorChecker : FirTypeOperatorCallCheck
else -> {}
}
}
}
}
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.classId
import org.jetbrains.kotlin.fir.types.coneTypeOrNull
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
@@ -174,9 +175,7 @@ object FirNativeThrowsChecker : FirBasicDeclarationChecker() {
val arguments = argumentList.arguments
return (arguments.firstOrNull() as? FirVarargArgumentsExpression)?.arguments
?.filterIsInstance<FirGetClassCall>()
?.map { it.arguments.first().typeRef }
?.filterIsInstance<FirResolvedTypeRef>()
?.map { it.type.fullyExpandedType(session) }
?.mapNotNull { it.arguments.first().coneTypeOrNull?.fullyExpandedType(session) }
?: emptyList()
}
@@ -78,7 +78,7 @@ object FirReturnsImpliesAnalyzer : FirControlFlowChecker() {
val isReturn = node is JumpNode && node.fir is FirReturnExpression
val resultExpression = if (isReturn) (node.fir as FirReturnExpression).result else node.fir
val expressionType = (resultExpression as? FirExpression)?.typeRef?.coneType
val expressionType = (resultExpression as? FirExpression)?.coneType
if (expressionType == builtinTypes.nothingType.type) return false
if (isReturn && resultExpression is FirWhenExpression) {
@@ -85,7 +85,7 @@ internal fun checkConstantArguments(
}
}
expression is FirGetClassCall -> {
var coneType = (expression as? FirCall)?.argument?.typeRef?.coneType
var coneType = (expression as? FirCall)?.argument?.coneType
if (coneType is ConeErrorType)
return ConstantArgumentKind.NOT_CONST
@@ -109,7 +109,7 @@ internal fun checkConstantArguments(
}
expressionSymbol is FirConstructorSymbol -> {
if (expression is FirCallableReferenceAccess) return null
if (expression.typeRef.coneType.isUnsignedType) {
if (expression.coneType.isUnsignedType) {
(expression as FirFunctionCall).arguments.forEach { argumentExpression ->
checkConstantArguments(argumentExpression, session)?.let { return it }
}
@@ -122,7 +122,7 @@ internal fun checkConstantArguments(
if (calleeReference is FirErrorNamedReference) {
return null
}
if (expression.typeRef.coneType.classId == StandardClassIds.KClass) {
if (expression.coneType.classId == StandardClassIds.KClass) {
return ConstantArgumentKind.NOT_KCLASS_LITERAL
}
@@ -140,7 +140,7 @@ internal fun checkConstantArguments(
for (exp in expression.arguments.plus(expression.dispatchReceiver).plus(expression.extensionReceiver)) {
if (exp is FirNoReceiverExpression) continue
val expClassId = exp.typeRef.coneType.lowerBoundIfFlexible().classId
val expClassId = exp.coneType.lowerBoundIfFlexible().classId
// TODO, KT-59823: add annotation for allowed constant types
if (expClassId !in StandardClassIds.constantAllowedTypes) {
return ConstantArgumentKind.NOT_CONST
@@ -152,7 +152,7 @@ internal fun checkConstantArguments(
return null
}
expression is FirQualifiedAccessExpression -> {
val expressionType = expression.typeRef.coneType
val expressionType = expression.coneType
if (expressionType.isReflectFunctionType(session) || expressionType.isKProperty(session) || expressionType.isKMutableProperty(session)) {
return checkConstantArguments(expression.dispatchReceiver, session)
}
@@ -195,7 +195,7 @@ private fun FirExpression.isForbiddenComplexConstant(session: FirSession): Boole
private val FirExpression.isComplexBooleanConstant
get(): Boolean = when {
!typeRef.coneType.isBoolean -> false
!coneType.isBoolean -> false
this is FirConstExpression<*> -> false
usesVariableAsConstant -> false
else -> true
@@ -231,7 +231,7 @@ private fun FirFunctionCall.isCompileTimeBuiltinCall(): Boolean {
val symbol = calleeReference.resolvedSymbol as? FirCallableSymbol
if (!symbol.fromKotlin()) return false
val coneType = this.dispatchReceiver.typeRef.coneTypeSafe<ConeKotlinType>()
val coneType = this.dispatchReceiver.coneTypeSafe<ConeKotlinType>()
val receiverClassId = coneType?.lowerBoundIfFlexible()?.classId
if (receiverClassId in StandardClassIds.unsignedTypes) return false
@@ -452,7 +452,7 @@ fun checkTypeMismatch(
isInitializer: Boolean
) {
var lValueType = lValueOriginalType
var rValueType = rValue.typeRef.coneType
var rValueType = rValue.coneType
if (source.kind is KtFakeSourceElementKind.DesugaredIncrementOrDecrement) {
if (!lValueType.isNullable && rValueType.isNullable) {
val tempType = rValueType
@@ -512,7 +512,7 @@ fun checkTypeMismatch(
}
internal fun checkCondition(condition: FirExpression, context: CheckerContext, reporter: DiagnosticReporter) {
val coneType = condition.typeRef.coneType.lowerBoundIfFlexible()
val coneType = condition.coneType.lowerBoundIfFlexible()
if (coneType !is ConeErrorType && !coneType.isSubtypeOf(context.session.typeContext, context.session.builtinTypes.booleanType.type)) {
reporter.reportOn(
condition.source,
@@ -40,13 +40,13 @@ object FirAmbiguousAnonymousTypeChecker : FirBasicDeclarationChecker() {
* 2. `val x = ...`
* 3. `val x get() = ...`
*/
val typeRef = when (declaration) {
is FirProperty -> declaration.initializer?.typeRef ?: declaration.getter?.body?.singleExpressionType
val type = when (declaration) {
is FirProperty -> declaration.initializer?.coneType ?: declaration.getter?.body?.singleExpressionType
is FirFunction -> declaration.body?.singleExpressionType
else -> error("Should not be there")
} ?: return
checkTypeAndArguments(typeRef.coneType, context, reporter, declaration.source)
checkTypeAndArguments(type, context, reporter, declaration.source)
}
private fun checkTypeAndArguments(
@@ -76,5 +76,5 @@ object FirAmbiguousAnonymousTypeChecker : FirBasicDeclarationChecker() {
}
private val FirBlock.singleExpressionType
get() = ((this as? FirSingleExpressionBlock)?.statement as? FirReturnExpression)?.result?.typeRef
get() = ((this as? FirSingleExpressionBlock)?.statement as? FirReturnExpression)?.result?.coneType
}
@@ -29,13 +29,13 @@ object FirDelegateFieldTypeMismatchChecker : FirRegularClassChecker() {
if (
!isReportedByErrorNodeDiagnosticCollector &&
!initializer.typeRef.coneType.isSubtypeOf(supertype.coneType, context.session, true)
!initializer.coneType.isSubtypeOf(supertype.coneType, context.session, true)
) {
reporter.reportOn(
initializer.source,
FirErrors.TYPE_MISMATCH,
field.returnTypeRef.coneType,
initializer.typeRef.coneType,
initializer.coneType,
false,
context,
)
@@ -24,7 +24,7 @@ object FirDelegateUsesExtensionPropertyTypeParameterChecker : FirPropertyChecker
val delegate = declaration.delegate as? FirFunctionCall ?: return
val parameters = declaration.typeParameters.mapTo(hashSetOf()) { it.symbol }
val usedTypeParameterSymbol = delegate.typeRef.coneType.findUsedTypeParameterSymbol(parameters, delegate, context, reporter)
val usedTypeParameterSymbol = delegate.coneType.findUsedTypeParameterSymbol(parameters, delegate, context, reporter)
?: return
reporter.reportOn(declaration.source, FirErrors.DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER, usedTypeParameterSymbol, context)
@@ -37,7 +37,7 @@ object FirDelegateUsesExtensionPropertyTypeParameterChecker : FirPropertyChecker
reporter: DiagnosticReporter,
): FirTypeParameterSymbol? {
val expandedDelegateClassLikeType =
delegate.typeRef.coneType.lowerBoundIfFlexible().fullyExpandedType(context.session)
delegate.coneType.lowerBoundIfFlexible().fullyExpandedType(context.session)
.unwrapDefinitelyNotNull() as? ConeClassLikeType ?: return null
val delegateClassSymbol = expandedDelegateClassLikeType.lookupTag.toSymbol(context.session) as? FirRegularClassSymbol ?: return null
val delegateClassScope by lazy { delegateClassSymbol.unsubstitutedScope(context) }
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.types.AbstractTypeChecker
object FirDelegatedPropertyChecker : FirPropertyChecker() {
override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) {
val delegate = declaration.delegate ?: return
val delegateType = delegate.typeRef.coneType
val delegateType = delegate.coneType
val source = delegate.source;
if (delegateType is ConeErrorType) {
@@ -66,7 +66,7 @@ object FirDelegatedPropertyChecker : FirPropertyChecker() {
val diagnostic = if (reference.isError()) reference.diagnostic else return false
if (reference.source?.kind != KtFakeSourceElementKind.DelegatedPropertyAccessor) return false
val expectedFunctionSignature =
(if (isGet) "getValue" else "setValue") + "(${functionCall.arguments.joinToString(", ") { it.typeRef.coneType.renderReadable() }})"
(if (isGet) "getValue" else "setValue") + "(${functionCall.arguments.joinToString(", ") { it.coneType.renderReadable() }})"
val delegateDescription = if (isGet) "delegate" else "delegate for var (read-write property)"
fun reportInapplicableDiagnostics(candidates: Collection<FirBasedSymbol<*>>) {
@@ -124,7 +124,7 @@ object FirDelegatedPropertyChecker : FirPropertyChecker() {
}
private fun checkReturnType(functionCall: FirFunctionCall) {
val returnType = functionCall.typeRef.coneType
val returnType = functionCall.coneType
val propertyType = declaration.returnTypeRef.coneType
if (!AbstractTypeChecker.isSubtypeOf(context.session.typeContext, returnType, propertyType)) {
reporter.reportOn(
@@ -68,7 +68,7 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() {
val originalDestructuringDeclarationType =
when (originalDestructuringDeclarationOrInitializer) {
is FirVariable -> originalDestructuringDeclarationOrInitializer.returnTypeRef.coneType
is FirExpression -> originalDestructuringDeclarationOrInitializer.typeRef.coneType
is FirExpression -> originalDestructuringDeclarationOrInitializer.coneType
else -> null
} ?: return
@@ -154,7 +154,7 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() {
}
}
is ConeConstraintSystemHasContradiction -> {
val componentType = componentCall.typeRef.coneType
val componentType = componentCall.coneType
if (componentType is ConeErrorType) {
// There will be other errors on this error type.
return
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.impl.FirPrimaryConstructor
@@ -26,6 +25,8 @@ import org.jetbrains.kotlin.fir.resolve.dfa.cfg.FunctionCallNode
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.QualifiedAccessNode
import org.jetbrains.kotlin.fir.resolve.dfa.controlFlowGraph
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import org.jetbrains.kotlin.utils.addToStdlib.lastIsInstanceOrNull
@@ -91,7 +92,7 @@ object FirEnumCompanionInEnumConstructorCallChecker : FirClassChecker() {
private fun FirExpression.getClassSymbol(session: FirSession): FirRegularClassSymbol? {
return when (this) {
is FirResolvedQualifier -> {
this.typeRef.toRegularClassSymbol(session)
this.coneType.toRegularClassSymbol(session)
}
else -> (this.toReference() as? FirThisReference)?.boundSymbol
} as? FirRegularClassSymbol
@@ -286,7 +286,7 @@ object FirInlineDeclarationChecker : FirFunctionChecker() {
} as? FirQualifiedAccessExpression ?: return
if (receiver.calleeReference is FirSuperReference) {
val dispatchReceiverType = receiver.dispatchReceiver.typeRef.coneType
val dispatchReceiverType = receiver.dispatchReceiver.coneType
val classSymbol = dispatchReceiverType.toSymbol(session) ?: return
if (!classSymbol.isDefinedInInlineFunction()) {
reporter.reportOn(
@@ -10,13 +10,14 @@ import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.config.AnalysisFlags
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.toClassLikeSymbol
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.expressions.FirStatement
import org.jetbrains.kotlin.fir.expressions.calleeReference
import org.jetbrains.kotlin.fir.packageFqName
import org.jetbrains.kotlin.fir.references.resolved
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.types.classId
import org.jetbrains.kotlin.fir.types.coneTypeOrNull
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
@@ -41,8 +42,7 @@ abstract class AbstractFirReflectionApiCallChecker : FirBasicExpressionChecker()
val resolvedReference = expression.calleeReference?.resolved ?: return
val referencedSymbol = resolvedReference.resolvedSymbol as? FirCallableSymbol ?: return
val containingClassId =
(expression as? FirQualifiedAccessExpression)?.dispatchReceiver?.typeRef?.toClassLikeSymbol(context.session)?.classId
val containingClassId = (expression as? FirQualifiedAccessExpression)?.dispatchReceiver?.coneTypeOrNull?.classId
if (containingClassId == null || containingClassId.packageFqName != StandardNames.KOTLIN_REFLECT_FQ_NAME) return
if (!isAllowedReflectionApi(referencedSymbol.name, containingClassId, context)) {
@@ -25,7 +25,7 @@ object FirAssignmentOperatorCallChecker : FirFunctionCallChecker() {
) {
return
}
if (!expression.typeRef.coneType.isUnit) {
if (!expression.coneType.isUnit) {
reporter.reportOn(
expression.source,
FirErrors.ASSIGNMENT_OPERATOR_SHOULD_RETURN_UNIT,
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.fir.types.coneType
object FirAssignmentTypeMismatchChecker : FirVariableAssignmentChecker() {
override fun check(expression: FirVariableAssignment, context: CheckerContext, reporter: DiagnosticReporter) {
val source = expression.rValue.source ?: return
val coneType = expression.lValue.typeRef.coneType
val coneType = expression.lValue.coneType
checkTypeMismatch(
coneType,
expression,
@@ -24,7 +24,7 @@ object FirCastOperatorsChecker : FirTypeOperatorCallChecker() {
override fun check(expression: FirTypeOperatorCall, context: CheckerContext, reporter: DiagnosticReporter) {
val session = context.session
val firstArgument = expression.argumentList.arguments[0]
val actualType = (firstArgument.unwrapSmartcastExpression().typeRef.coneType).fullyExpandedType(session)
val actualType = firstArgument.unwrapSmartcastExpression().coneType.fullyExpandedType(session)
val conversionTypeRef = expression.conversionTypeRef
val targetType = conversionTypeRef.coneType.fullyExpandedType(session)
@@ -49,8 +49,8 @@ object FirClassLiteralChecker : FirGetClassCallChecker() {
val markedNullable = source.getChild(QUEST, depth = 1) != null
val isNullable = markedNullable ||
(argument as? FirResolvedQualifier)?.isNullableLHSForCallableReference == true ||
argument.typeRef.coneType.isMarkedNullable ||
argument.typeRef.coneType.isNullableTypeParameter(context.session.typeContext)
argument.coneType.isMarkedNullable ||
argument.coneType.isNullableTypeParameter(context.session.typeContext)
if (isNullable) {
if (argument.canBeDoubleColonLHSAsType) {
reporter.reportOn(source, FirErrors.NULLABLE_TYPE_IN_CLASS_LITERAL_LHS, context)
@@ -58,7 +58,7 @@ object FirClassLiteralChecker : FirGetClassCallChecker() {
reporter.reportOn(
argument.source,
FirErrors.EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS,
argument.typeRef.coneType,
argument.coneType,
context
)
}
@@ -74,7 +74,7 @@ object FirClassLiteralChecker : FirGetClassCallChecker() {
if (argument !is FirResolvedQualifier) return
// TODO, KT-59835: differentiate RESERVED_SYNTAX_IN_CALLABLE_REFERENCE_LHS
if (argument.typeArguments.isNotEmpty() && !argument.typeRef.coneType.fullyExpandedType(context.session).isAllowedInClassLiteral(context)) {
if (argument.typeArguments.isNotEmpty() && !argument.coneType.fullyExpandedType(context.session).isAllowedInClassLiteral(context)) {
val symbol = argument.symbol
symbol?.lazyResolveToPhase(FirResolvePhase.TYPES)
@OptIn(SymbolInternals::class)
@@ -352,10 +352,10 @@ private class ArgumentInfo(
private val FirExpression.mostOriginalTypeIfSmartCast: ConeKotlinType
get() = when (this) {
is FirSmartCastExpression -> originalExpression.mostOriginalTypeIfSmartCast
else -> typeRef.coneType
else -> coneType
}
private fun FirExpression.toArgumentInfo(context: CheckerContext) =
ArgumentInfo(
this, typeRef.coneType, mostOriginalTypeIfSmartCast.fullyExpandedType(context.session), context.session,
this, coneType, mostOriginalTypeIfSmartCast.fullyExpandedType(context.session), context.session,
)
@@ -41,7 +41,7 @@ object FirExhaustiveWhenChecker : FirWhenExpressionChecker() {
val source = whenExpression.source ?: return
val subjectType = whenExpression.subject?.typeRef?.coneType?.lowerBoundIfFlexible()
val subjectType = whenExpression.subject?.coneType?.lowerBoundIfFlexible()
val subjectClassSymbol = subjectType?.fullyExpandedType(context.session)?.toRegularClassSymbol(context.session)
if (whenExpression.usedAsExpression) {
@@ -56,7 +56,7 @@ object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() {
}
val typeContext = context.session.typeContext
val returnExpressionType = resultExpression.typeRef.coneType
val returnExpressionType = resultExpression.coneType
if (!isSubtypeForTypeMismatch(typeContext, subtype = returnExpressionType, supertype = functionReturnType)) {
if (resultExpression.isNullLiteral && functionReturnType.nullability == ConeNullability.NOT_NULL) {
@@ -70,7 +70,7 @@ object FirNamedVarargChecker : FirCallChecker() {
if (expression is FirArrayLiteral) {
// FirArrayLiteral has the `vararg` argument expression pre-flattened and doesn't have an argument mapping.
expression.arguments.forEach { checkArgument(it, it is FirNamedArgumentExpression, expression.typeRef.coneTypeOrNull) }
expression.arguments.forEach { checkArgument(it, it is FirNamedArgumentExpression, expression.coneTypeOrNull) }
} else {
val argumentMap = expression.resolvedArgumentMapping ?: return
for ((argument, parameter) in argumentMap) {
@@ -30,13 +30,12 @@ object FirNotNullAssertionChecker : FirCheckNotNullCallChecker() {
}
// TODO: use of Unit is subject to change.
// See BodyResolveComponents.typeForQualifier in ResolveUtils.kt which returns Unit for no value type.
@OptIn(UnexpandedTypeCheck::class)
if (argument is FirResolvedQualifier && argument.typeRef.isUnit) {
if (argument is FirResolvedQualifier && argument.coneType.isUnit) {
// Would be reported as NO_COMPANION_OBJECT
return
}
val type = argument.typeRef.coneType.fullyExpandedType(context.session)
val type = argument.coneType.fullyExpandedType(context.session)
if (!type.canBeNull && context.languageVersionSettings.supportsFeature(LanguageFeature.EnableDfaWarningsInK2)) {
reporter.reportOn(expression.source, FirErrors.UNNECESSARY_NOT_NULL_ASSERTION, type, context)
@@ -35,7 +35,7 @@ object FirOptInUsageAccessChecker : FirBasicExpressionChecker() {
reportNotAcceptedExperimentalities(experimentalities, expression.lValue, context, reporter)
} else if (expression is FirQualifiedAccessExpression) {
val dispatchReceiverType =
expression.dispatchReceiver.takeIf { it !is FirNoReceiverExpression }?.typeRef?.coneType?.fullyExpandedType(context.session)
expression.dispatchReceiver.takeIf { it !is FirNoReceiverExpression }?.coneType?.fullyExpandedType(context.session)
val experimentalities = resolvedSymbol.loadExperimentalities(context, fromSetter = false, dispatchReceiverType) +
loadExperimentalitiesFromTypeArguments(context, expression.typeArguments)
@@ -25,6 +25,8 @@ import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeDiagnosticWithCandidates
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
import org.jetbrains.kotlin.fir.visibilityChecker
object FirReassignmentAndInvisibleSetterChecker : FirVariableAssignmentChecker() {
@@ -62,7 +64,7 @@ object FirReassignmentAndInvisibleSetterChecker : FirVariableAssignmentChecker()
val explicitReceiver = expression.explicitReceiver
// Try to get type from smartcast
if (explicitReceiver is FirSmartCastExpression) {
val symbol = explicitReceiver.originalExpression.typeRef.toRegularClassSymbol(context.session)
val symbol = explicitReceiver.originalExpression.coneType.toRegularClassSymbol(context.session)
if (symbol != null) {
for (declarationSymbol in symbol.declarationSymbols) {
if (declarationSymbol is FirPropertySymbol && declarationSymbol.name == callableSymbol.name) {
@@ -37,8 +37,8 @@ object FirRecursiveProblemChecker : FirBasicExpressionChecker() {
}
}
checkConeType(expression.typeRef.coneType)
checkConeType(expression.coneType)
}
private val FirStatement.isExpressionWithAlwaysImplicitTypeRef get() = this is FirNoReceiverExpression
}
}
@@ -21,8 +21,8 @@ import org.jetbrains.kotlin.fir.types.coneType
object FirSpreadOfNullableChecker : FirFunctionCallChecker() {
override fun check(expression: FirFunctionCall, context: CheckerContext, reporter: DiagnosticReporter) {
fun checkAndReport(argument: FirExpression, source: KtSourceElement?) {
val argumentTypeRef = argument.typeRef
if (argument is FirSpreadArgumentExpression && argumentTypeRef.coneType !is ConeFlexibleType && argumentTypeRef.canBeNull) {
val coneType = argument.coneType
if (argument is FirSpreadArgumentExpression && coneType !is ConeFlexibleType && coneType.canBeNull) {
reporter.reportOn(source, FirErrors.SPREAD_OF_NULLABLE, context)
}
}
@@ -37,4 +37,4 @@ object FirSpreadOfNullableChecker : FirFunctionCallChecker() {
}
}
}
}
}
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
import org.jetbrains.kotlin.fir.types.UnexpandedTypeCheck
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.isUnit
object FirStandaloneQualifierChecker : FirResolvedQualifierChecker() {
@@ -29,8 +30,7 @@ object FirStandaloneQualifierChecker : FirResolvedQualifierChecker() {
if (lastGetClass?.argument === expression) return
// Note: if it's real Unit, it will be filtered by ClassKind.OBJECT check below in reportErrorOn
@OptIn(UnexpandedTypeCheck::class)
if (!expression.typeRef.isUnit) return
if (!expression.coneType.isUnit) return
expression.symbol.reportErrorOn(expression.source, context, reporter)
}
@@ -165,7 +165,7 @@ object FirSuspendCallChecker : FirQualifiedAccessExpressionChecker() {
expression.computeReceiversInfo(session, calledDeclarationSymbol)
for (receiverExpression in listOfNotNull(dispatchReceiverExpression, extensionReceiverExpression)) {
if (!receiverExpression.typeRef.coneType.isRestrictSuspensionReceiver(session)) continue
if (!receiverExpression.coneType.isRestrictSuspensionReceiver(session)) continue
if (sameInstanceOfReceiver(receiverExpression, enclosingSuspendFunctionDispatchReceiverOwnerSymbol)) continue
if (sameInstanceOfReceiver(receiverExpression, enclosingSuspendFunctionExtensionReceiverOwnerSymbol)) continue
@@ -221,10 +221,10 @@ object FirSuspendCallChecker : FirQualifiedAccessExpressionChecker() {
calledDeclarationSymbol: FirCallableSymbol<*>
): Triple<FirExpression?, FirExpression?, ConeKotlinType?> {
if (this is FirImplicitInvokeCall &&
dispatchReceiver != FirNoReceiverExpression && dispatchReceiver.typeRef.coneType.isSuspendOrKSuspendFunctionType(session)
dispatchReceiver != FirNoReceiverExpression && dispatchReceiver.coneType.isSuspendOrKSuspendFunctionType(session)
) {
val variableForInvoke = dispatchReceiver
val variableForInvokeType = variableForInvoke.typeRef.coneType
val variableForInvokeType = variableForInvoke.coneType
if (!variableForInvokeType.isExtensionFunctionType) return Triple(null, null, null)
// `a.foo()` is resolved to invokeExtension, so it's been desugared to `foo.invoke(a)`
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.fir.types.typeContext
object FirThrowExpressionTypeChecker : FirThrowExpressionChecker() {
override fun check(expression: FirThrowExpression, context: CheckerContext, reporter: DiagnosticReporter) {
val expectedType = context.session.builtinTypes.throwableType.coneType
val actualType = expression.exception.typeRef.coneType
val actualType = expression.exception.coneType
if (!actualType.isSubtypeOf(expectedType, context.session)) {
reporter.reportOn(
@@ -31,4 +31,4 @@ object FirThrowExpressionTypeChecker : FirThrowExpressionChecker() {
)
}
}
}
}
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.fir.types.isUnit
object FirUnnecessarySafeCallChecker : FirSafeCallExpressionChecker() {
override fun check(expression: FirSafeCallExpression, context: CheckerContext, reporter: DiagnosticReporter) {
val receiverType = expression.receiver.typeRef.coneType.fullyExpandedType(context.session)
val receiverType = expression.receiver.coneType.fullyExpandedType(context.session)
if (expression.receiver.source?.elementType == KtNodeTypes.SUPER_EXPRESSION) {
reporter.reportOn(expression.source, FirErrors.UNEXPECTED_SAFE_CALL, context)
return
@@ -9,13 +9,14 @@ import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.declarations.impl.FirPrimaryConstructor
import org.jetbrains.kotlin.fir.declarations.utils.isCompanion
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
object FirUnsupportedArrayLiteralChecker : FirArrayLiteralChecker() {
override fun check(expression: FirArrayLiteral, context: CheckerContext, reporter: DiagnosticReporter) {
@@ -35,7 +36,7 @@ object FirUnsupportedArrayLiteralChecker : FirArrayLiteralChecker() {
context.callsOrAssignments.lastOrNull()?.let {
val arguments = when (it) {
is FirFunctionCall ->
if (it.typeRef.toRegularClassSymbol(context.session)?.classKind == ClassKind.ANNOTATION_CLASS) {
if (it.coneType.toRegularClassSymbol(context.session)?.classKind == ClassKind.ANNOTATION_CLASS) {
it.arguments
} else {
return false
@@ -45,7 +45,7 @@ object FirUpperBoundViolatedExpressionChecker : FirQualifiedAccessExpressionChec
val typeParameters: List<FirTypeParameterSymbol>
if (calleeSymbol is FirConstructorSymbol && calleeSymbol.isTypeAliasedConstructor) {
val constructedType = expression.typeRef.coneType.fullyExpandedType(context.session)
val constructedType = expression.coneType.fullyExpandedType(context.session)
// Updating arguments with source information after expanding the type seems extremely brittle as it relies on identity equality
// of the expression type arguments and the expanded type arguments. This cannot be applied before expanding the type because it
// seems like the type is already expended.
@@ -21,9 +21,9 @@ object FirUselessElvisChecker : FirElvisExpressionChecker() {
// If the overall expression is not resolved/completed, the corresponding error will be reported separately.
// See [FirControlFlowStatementsResolveTransformer#transformElvisExpression],
// where an error type is recorded as the expression's return type.
if (expression.typeRef.coneType is ConeErrorType) return
if (expression.coneType is ConeErrorType) return
val lhsType = expression.lhs.typeRef.coneType
val lhsType = expression.lhs.coneType
if (lhsType is ConeErrorType) return
if (!lhsType.canBeNull) {
if (context.languageVersionSettings.supportsFeature(LanguageFeature.EnableDfaWarningsInK2)) {
@@ -21,7 +21,7 @@ object FirUselessTypeOperationCallChecker : FirTypeOperatorCallChecker() {
if (expression.operation !in FirOperation.TYPES) return
val arg = expression.argument
val candidateType = arg.typeRef.coneType.upperBoundIfFlexible().fullyExpandedType(context.session)
val candidateType = arg.coneType.upperBoundIfFlexible().fullyExpandedType(context.session)
if (candidateType is ConeErrorType) return
val targetType = expression.conversionTypeRef.coneType.fullyExpandedType(context.session)
@@ -26,8 +26,8 @@ object ArrayEqualityCanBeReplacedWithEquals : FirBasicExpressionChecker() {
val left = arguments.getOrNull(0) ?: return
val right = arguments.getOrNull(1) ?: return
if (left.typeRef.coneType.classId != StandardClassIds.Array) return
if (right.typeRef.coneType.classId != StandardClassIds.Array) return
if (left.coneType.classId != StandardClassIds.Array) return
if (right.coneType.classId != StandardClassIds.Array) return
reporter.reportOn(expression.source, ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS, context)
}
@@ -39,7 +39,7 @@ object CanBeReplacedWithOperatorAssignmentChecker : FirVariableAssignmentChecker
val rValue = expression.rValue as? FirFunctionCall ?: return
if (rValue.source?.kind is KtFakeSourceElementKind) return
if (rValue.explicitReceiver?.typeRef?.coneType?.isPrimitive != true) return
if (rValue.explicitReceiver?.coneType?.isPrimitive != true) return
val rValueResolvedSymbol = rValue.toResolvedCallableSymbol() ?: return
if (rValueResolvedSymbol.dispatchReceiverClassTypeOrNull()?.isPrimitive != true) return
@@ -36,14 +36,14 @@ object RedundantCallOfConversionMethod : FirQualifiedAccessExpressionChecker() {
private fun FirExpression.isRedundant(qualifiedClassId: ClassId): Boolean {
val thisType = if (this is FirConstExpression<*>) {
this.typeRef.coneType.classId
this.coneType.classId
} else {
when {
typeRef.coneType is ConeFlexibleType -> null
coneType is ConeFlexibleType -> null
psi?.parent !is KtSafeQualifiedExpression
&& (psi is KtSafeQualifiedExpression || typeRef.coneType.isMarkedNullable) -> null
this.typeRef.coneType.isMarkedNullable -> null
else -> this.typeRef.coneType.classId
&& (psi is KtSafeQualifiedExpression || coneType.isMarkedNullable) -> null
this.coneType.isMarkedNullable -> null
else -> this.coneType.classId
}
}
return thisType == qualifiedClassId
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.util.getChildren
object RedundantSingleExpressionStringTemplateChecker : FirStringConcatenationCallChecker() {
override fun check(expression: FirStringConcatenationCall, context: CheckerContext, reporter: DiagnosticReporter) {
for (argumentExpression in expression.arguments) {
if (argumentExpression.typeRef.coneType.classId == StandardClassIds.String &&
if (argumentExpression.coneType.classId == StandardClassIds.String &&
argumentExpression.stringParentChildrenCount() == 1 // there is no more children in original string template
) {
reporter.reportOn(argumentExpression.source, REDUNDANT_SINGLE_EXPRESSION_STRING_TEMPLATE, context)
@@ -37,10 +37,10 @@ object UselessCallOnNotNullChecker : FirQualifiedAccessExpressionChecker() {
}
private fun FirExpression.getPackage(): String {
return typeRef.coneType.classId?.packageFqName.toString()
return coneType.classId?.packageFqName.toString()
}
private fun FirExpression.getNullability() = typeRef.coneType.nullability
private fun FirExpression.getNullability() = coneType.nullability
private val triggerOn = setOf(
@@ -119,7 +119,7 @@ internal object FirToConstantValueTransformer : FirDefaultVisitor<ConstantValue<
getClassCall: FirGetClassCall,
data: FirToConstantValueTransformerData
): ConstantValue<*>? {
return create(getClassCall.argument.typeRef.coneTypeUnsafe())
return create(getClassCall.argument.coneTypeUnsafe())
}
override fun visitQualifiedAccessExpression(
@@ -158,7 +158,7 @@ internal object FirToConstantValueTransformer : FirDefaultVisitor<ConstantValue<
data.constValueProvider
)?.addEmptyVarargValuesFor(symbol)
?: return null
return AnnotationValue.create(qualifiedAccessExpression.typeRef.coneType, mapping)
return AnnotationValue.create(qualifiedAccessExpression.coneType, mapping)
}
symbol.callableId.packageName.asString() == "kotlin" -> {
@@ -262,7 +262,7 @@ internal object FirToConstantValueChecker : FirDefaultVisitor<Boolean, FirSessio
override fun visitAnnotationCall(annotationCall: FirAnnotationCall, data: FirSession): Boolean = true
override fun visitGetClassCall(getClassCall: FirGetClassCall, data: FirSession): Boolean {
return create(getClassCall.argument.typeRef.coneTypeUnsafe()) != null
return create(getClassCall.argument.coneTypeUnsafe()) != null
}
override fun visitQualifiedAccessExpression(qualifiedAccessExpression: FirQualifiedAccessExpression, data: FirSession): Boolean {
@@ -246,7 +246,7 @@ private fun FirCallableSymbol<*>.toSymbolForCall(
}
// Member fake override or bound callable reference
dispatchReceiver !is FirNoReceiverExpression -> {
val callSiteDispatchReceiverType = dispatchReceiver.typeRef.coneType
val callSiteDispatchReceiverType = dispatchReceiver.coneType
val declarationSiteDispatchReceiverType = dispatchReceiverType
val type = if (callSiteDispatchReceiverType is ConeDynamicType && declarationSiteDispatchReceiverType != null) {
declarationSiteDispatchReceiverType
@@ -296,7 +296,7 @@ private fun FirCallableSymbol<*>.toSymbolForCall(
fun FirConstExpression<*>.getIrConstKind(): IrConstKind<*> = when (kind) {
ConstantValueKind.IntegerLiteral, ConstantValueKind.UnsignedIntegerLiteral -> {
val type = typeRef.coneTypeUnsafe<ConeIntegerLiteralType>()
val type = coneTypeUnsafe<ConeIntegerLiteralType>()
type.getApproximatedType().toConstKind()!!.toIrConstKind()
}
@@ -966,7 +966,7 @@ class Fir2IrVisitor(
val receiver = statements.findFirst<FirProperty>() ?: return null
val receiverValue = receiver.initializer ?: return null
if (receiverValue.typeRef.coneType !is ConeDynamicType) {
if (receiverValue.coneType !is ConeDynamicType) {
return null
}
@@ -28,8 +28,8 @@ fun FirComparisonExpression.inferPrimitiveNumericComparisonInfo(): PrimitiveCone
inferPrimitiveNumericComparisonInfo(left, right)
fun inferPrimitiveNumericComparisonInfo(left: FirExpression, right: FirExpression): PrimitiveConeNumericComparisonInfo? {
val leftType = left.typeRef.coneType
val rightType = right.typeRef.coneType
val leftType = left.coneType
val rightType = right.coneType
val leftPrimitiveOrNullableType = leftType.getPrimitiveTypeOrSupertype() ?: return null
val rightPrimitiveOrNullableType = rightType.getPrimitiveTypeOrSupertype() ?: return null
val leastCommonType = leastCommonPrimitiveNumericType(leftPrimitiveOrNullableType, rightPrimitiveOrNullableType)
@@ -450,7 +450,7 @@ internal class AdapterGenerator(
if (!samType.isSamType) return this
return IrTypeOperatorCallImpl(
this.startOffset, this.endOffset, samType, IrTypeOperator.SAM_CONVERSION, samType,
castArgumentToFunctionalInterfaceForSamType(this, argument.typeRef.coneType, samFirType)
castArgumentToFunctionalInterfaceForSamType(this, argument.coneType, samFirType)
)
}
@@ -556,7 +556,7 @@ internal class AdapterGenerator(
session.typeContext.newTypeCheckerState(
errorTypesEqualToAnything = false, stubTypesEqualToAnything = true
),
argument.typeRef.coneType,
argument.coneType,
parameter.returnTypeRef.coneType,
isFromNullabilityConstraint = true
)
@@ -638,7 +638,7 @@ internal class AdapterGenerator(
expectedFunctionalType: ConeClassLikeType,
argument: FirExpression
): IrSimpleFunctionSymbol? {
val argumentType = argument.typeRef.coneType
val argumentType = argument.coneType
val argumentTypeWithInvoke = argumentType.findSubtypeOfBasicFunctionType(session, expectedFunctionalType) ?: return null
return if (argumentTypeWithInvoke.isSomeFunctionType(session)) {
@@ -73,7 +73,7 @@ class CallAndReferenceGenerator(
explicitReceiverExpression: IrExpression?,
isDelegate: Boolean
): IrExpression {
val type = approximateFunctionReferenceType(callableReferenceAccess.typeRef.coneType).toIrType()
val type = approximateFunctionReferenceType(callableReferenceAccess.coneType).toIrType()
val callableSymbol = callableReferenceAccess.calleeReference.toResolvedCallableSymbol()
if (callableSymbol?.origin == FirDeclarationOrigin.SamConstructor) {
@@ -106,7 +106,7 @@ class CallAndReferenceGenerator(
val referencedProperty = symbol.owner
val referencedPropertyGetter = referencedProperty.getter
val referencedPropertySetterSymbol =
if (callableReferenceAccess.typeRef.coneType.isKMutableProperty(session)) referencedProperty.setter?.symbol
if (callableReferenceAccess.coneType.isKMutableProperty(session)) referencedProperty.setter?.symbol
else null
val backingFieldSymbol = when {
referencedPropertyGetter != null -> null
@@ -163,7 +163,7 @@ class CallAndReferenceGenerator(
// Receivers are being applied inside
with(adapterGenerator) {
// TODO: Figure out why `adaptedType` is different from the `type`?
val adaptedType = callableReferenceAccess.typeRef.coneType.toIrType() as IrSimpleType
val adaptedType = callableReferenceAccess.coneType.toIrType() as IrSimpleType
generateAdaptedCallableReference(callableReferenceAccess, explicitReceiverExpression, symbol, adaptedType)
}
} else {
@@ -791,7 +791,7 @@ class CallAndReferenceGenerator(
qualifier: FirResolvedQualifier,
callableReferenceAccess: FirCallableReferenceAccess?
): IrExpression? {
val classSymbol = (qualifier.typeRef.coneType as? ConeClassLikeType)?.lookupTag?.toSymbol(session)
val classSymbol = (qualifier.coneType as? ConeClassLikeType)?.lookupTag?.toSymbol(session)
if (callableReferenceAccess?.isBound == false) {
return null
@@ -91,7 +91,7 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I
memberRequiredPhase = null,
)
val delegateToScope = firField.initializer!!.typeRef.coneType
val delegateToScope = firField.initializer!!.coneType
.fullyExpandedType(session)
.lowerBoundIfFlexible()
.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing, null) ?: return
@@ -46,7 +46,7 @@ internal class OperatorExpressionGenerator(
val operation = comparisonExpression.operation
val receiver = comparisonExpression.compareToCall.explicitReceiver
if (receiver?.typeRef?.coneType is ConeDynamicType) {
if (receiver?.coneType is ConeDynamicType) {
val dynamicOperator = operation.toIrDynamicOperator()
?: throw Exception("Can't convert to the corresponding IrDynamicOperator")
val argument = comparisonExpression.compareToCall.dynamicVarargArguments?.firstOrNull()
@@ -241,7 +241,7 @@ internal class OperatorExpressionGenerator(
comparisonInfo: PrimitiveConeNumericComparisonInfo?,
isLeftType: Boolean
): IrExpression {
val isOriginalNullable = (this as? FirSmartCastExpression)?.originalExpression?.typeRef?.isMarkedNullable ?: false
val isOriginalNullable = (this as? FirSmartCastExpression)?.originalExpression?.coneType?.isMarkedNullable ?: false
val irExpression = visitor.convertToIrExpression(this)
val operandType = if (isLeftType) comparisonInfo?.leftType else comparisonInfo?.rightType
val targetType = comparisonInfo?.comparisonType
@@ -97,7 +97,7 @@ internal class AnnotationsLoader(private val session: FirSession, private val ko
visitExpression(name, buildArrayLiteral {
guessArrayTypeIfNeeded(name, elements)?.let {
typeRef = it
} ?: elements.firstOrNull()?.typeRef?.coneType?.createOutArrayType()?.let {
} ?: elements.firstOrNull()?.coneType?.createOutArrayType()?.let {
typeRef = buildResolvedTypeRef {
type = it
}
@@ -84,7 +84,7 @@ fun List<FirAnnotation>.computeTypeAttributes(
for (annotation in this) {
val classId = when (shouldExpandTypeAliases) {
true -> annotation.tryExpandClassId(session)
false -> annotation.typeRef.coneType.classId
false -> annotation.coneType.classId
}
when (classId) {
CompilerConeAttributes.Exact.ANNOTATION_CLASS_ID -> attributes += CompilerConeAttributes.Exact
@@ -287,7 +287,7 @@ abstract class FirVisibilityChecker : FirSessionComponent {
val dispatchReceiverParameterClassLookupTag = dispatchReceiverParameterClassSymbol.toLookupTag()
val dispatchReceiverValueOwnerLookupTag =
dispatchReceiver.typeRef.coneType.findClassRepresentation(
dispatchReceiver.coneType.findClassRepresentation(
dispatchReceiverParameterClassLookupTag.constructClassType(
Array(dispatchReceiverParameterClassSymbol.fir.typeParameters.size) { ConeStarProjection },
isNullable = true
@@ -364,10 +364,10 @@ abstract class FirVisibilityChecker : FirSessionComponent {
session: FirSession
): Boolean {
if (dispatchReceiver == null) return true
var dispatchReceiverType = dispatchReceiver.typeRef.coneType
var dispatchReceiverType = dispatchReceiver.coneType
if (dispatchReceiver is FirPropertyAccessExpression && dispatchReceiver.calleeReference is FirSuperReference) {
// Special 'super' case: type of this, not of super, should be taken for the check below
dispatchReceiverType = dispatchReceiver.dispatchReceiver.typeRef.coneType
dispatchReceiverType = dispatchReceiver.dispatchReceiver.coneType
}
val typeCheckerState = session.typeContext.newTypeCheckerState(
errorTypesEqualToAnything = false,
@@ -394,7 +394,7 @@ abstract class FirVisibilityChecker : FirSessionComponent {
private fun FirExpression?.ownerIfCompanion(session: FirSession): ConeClassLikeLookupTag? =
// TODO: what if there is an intersection type from smartcast?
(this?.typeRef?.coneType as? ConeClassLikeType)?.lookupTag?.ownerIfCompanion(session)
(this?.coneType as? ConeClassLikeType)?.lookupTag?.ownerIfCompanion(session)
// monitorEnter/monitorExit are the only functions which are accessed "illegally" (see kotlin/util/Synchronized.kt).
// Since they are intrinsified in the codegen, FIR should treat it as visible.
@@ -508,7 +508,7 @@ private fun FirMemberDeclaration.containingNonLocalClass(
if (dispatchReceiver != null) {
val baseReceiverType = dispatchReceiverClassTypeOrNull()
if (baseReceiverType != null) {
dispatchReceiver.typeRef.coneType.findClassRepresentation(baseReceiverType, session)?.toSymbol(session)?.fir?.let {
dispatchReceiver.coneType.findClassRepresentation(baseReceiverType, session)?.toSymbol(session)?.fir?.let {
return it
}
}
@@ -240,7 +240,7 @@ fun FirAnnotation.getKClassArgument(name: Name): ConeKotlinType? {
}
fun FirGetClassCall.getTargetType(): ConeKotlinType? {
return typeRef.coneType.typeArguments.getOrNull(0)?.type
return coneType.typeArguments.getOrNull(0)?.type
}
fun FirAnnotationContainer.getJvmNameFromAnnotation(session: FirSession, target: AnnotationUseSiteTarget? = null): String? {
@@ -41,7 +41,7 @@ fun FirSmartCastExpression.smartcastScope(
return smartcastScope
}
val originalScope = originalExpression.typeRef.coneType.scope(
val originalScope = originalExpression.coneType.scope(
useSiteSession = useSiteSession,
scopeSession = scopeSession,
fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
@@ -50,7 +50,7 @@ abstract class ReceiverValue {
class ExpressionReceiverValue(override val receiverExpression: FirExpression) : ReceiverValue() {
override val type: ConeKotlinType
// NB: safe cast is necessary here
get() = receiverExpression.typeRef.coneTypeSafe()
get() = receiverExpression.coneTypeSafe()
?: ConeErrorType(ConeIntermediateDiagnostic("No type calculated for: ${receiverExpression.renderWithType()}")) // TODO: assert here
override fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? {
@@ -549,7 +549,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
}
val customAnnotations = attributes.customAnnotations
return customAnnotations.any {
it.typeRef.coneTypeSafe<ConeKotlinType>()?.fullyExpandedType(session)?.classId?.asSingleFqName() == fqName
it.coneTypeSafe<ConeKotlinType>()?.fullyExpandedType(session)?.classId?.asSingleFqName() == fqName
}
}
@@ -558,7 +558,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
// We don't check for compiler attributes because all of them doesn't have parameters
val customAnnotations = attributes.customAnnotations
val annotationCall = customAnnotations.firstOrNull {
it.typeRef.coneTypeSafe<ConeKotlinType>()?.fullyExpandedType(session)?.classId?.asSingleFqName() == fqName
it.coneTypeSafe<ConeKotlinType>()?.fullyExpandedType(session)?.classId?.asSingleFqName() == fqName
} ?: return null
val argument = when (val argument = annotationCall.argumentMapping.mapping.values.firstOrNull() ?: return null) {
is FirVarargArgumentsExpression -> argument.arguments.firstOrNull()
@@ -585,7 +585,7 @@ class FirCallResolver(
//calleeReference and annotationTypeRef are both error nodes so we need to avoid doubling of the diagnostic report
else ConeStubDiagnostic(
//prefer diagnostic with symbol, e.g. to use the symbol during navigation in IDE
(annotation.typeRef.coneType as? ConeErrorType)?.diagnostic as? ConeDiagnosticWithSymbol<*>
(annotation.coneType as? ConeErrorType)?.diagnostic as? ConeDiagnosticWithSymbol<*>
?: ConeUnresolvedNameError(reference.name)),
reference.source
)
@@ -722,7 +722,7 @@ class FirCallResolver(
ConeResolutionToClassifierError(singleExpectedCandidate!!, fir.symbol)
}
else -> {
val coneType = explicitReceiver?.typeRef?.coneType
val coneType = explicitReceiver?.coneType
when {
coneType != null && !coneType.isUnit -> {
ConeFunctionExpectedError(
@@ -751,7 +751,7 @@ class FirCallResolver(
name.asString() == "invoke" && explicitReceiver is FirConstExpression<*> ->
ConeFunctionExpectedError(
explicitReceiver.value?.toString() ?: "",
explicitReceiver.typeRef.coneType,
explicitReceiver.coneType,
)
reference is FirSuperReference && (reference.superTypeRef.firClassLike(session) as? FirClass)?.isInterface == true -> ConeNoConstructorError
else -> ConeUnresolvedNameError(name)
@@ -810,7 +810,7 @@ class FirCallResolver(
*/
if (components.context.inferenceSession !is FirBuilderInferenceSession &&
createResolvedReferenceWithoutCandidateForLocalVariables &&
explicitReceiver?.typeRef?.coneTypeSafe<ConeIntegerLiteralType>() == null &&
explicitReceiver?.coneTypeSafe<ConeIntegerLiteralType>() == null &&
coneSymbol is FirVariableSymbol &&
(coneSymbol !is FirPropertySymbol || (coneSymbol.fir as FirMemberDeclaration).typeParameters.isEmpty())
) {
@@ -119,7 +119,7 @@ class FirDoubleColonExpressionResolver(private val session: FirSession) {
}
private fun resolveExpressionOnLHS(expression: FirExpression): DoubleColonLHS.Expression? {
val type = expression.typeRef.coneType
val type = expression.coneType
if (expression is FirResolvedQualifier) {
val firClass = expression.expandedRegularClassIfAny() ?: return null
@@ -414,7 +414,7 @@ private fun <T : FirExpression> BodyResolveComponents.transformExpressionUsingSm
SmartcastStability.STABLE_VALUE
}
val originalType = expression.resultType.coneType.fullyExpandedType(session)
val originalType = expression.coneType.fullyExpandedType(session)
val allTypes = typesFromSmartCast.also {
if (originalType !is ConeStubType) {
it += originalType.fullyExpandedType(session)
@@ -495,7 +495,7 @@ fun FirSafeCallExpression.propagateTypeFromQualifiedAccessAfterNullCheck(
val resultingType = when {
selector is FirExpression && !selector.isCallToStatementLikeFunction -> {
val type = selector.typeRef.coneTypeSafe<ConeKotlinType>() ?: return
val type = selector.coneTypeSafe<ConeKotlinType>() ?: return
type.withNullability(ConeNullability.NULLABLE, session.typeContext)
}
// Branch for things that shouldn't be used as expressions.
@@ -147,7 +147,7 @@ private fun Candidate.resolveBlockArgument(
checkApplicabilityForArgumentType(
csBuilder,
block,
block.typeRef.coneType,
block.coneType,
expectedType?.type,
SimpleConstraintSystemConstraintPosition,
isReceiver = false,
@@ -222,7 +222,7 @@ fun Candidate.resolvePlainExpressionArgument(
) {
if (expectedType == null) return
val argumentType = argument.typeRef.coneTypeSafe<ConeKotlinType>() ?: return
val argumentType = argument.coneTypeSafe<ConeKotlinType>() ?: return
resolvePlainArgumentType(
csBuilder,
argument,
@@ -513,7 +513,7 @@ private fun getExpectedTypeWithImplicintIntegerCoercion(
val argumentType =
if (argument.isIntegerLiteralOrOperatorCall()) {
if (candidateExpectedType.fullyExpandedType(session).isUnsignedTypeOrNullableUnsignedType)
argument.resultType.coneType
argument.coneType
else null
} else {
argument.calleeReference?.toResolvedCallableSymbol()?.takeIf {
@@ -534,7 +534,7 @@ fun FirExpression.isFunctional(
is FirAnonymousFunctionExpression, is FirCallableReferenceAccess -> return true
else -> {
// Either a functional type or a subtype of a class that has a contributed `invoke`.
val coneType = typeRef.coneTypeSafe<ConeKotlinType>() ?: return false
val coneType = coneTypeSafe<ConeKotlinType>() ?: return false
if (coneType.isSomeFunctionType(session)) {
return true
}
@@ -135,7 +135,7 @@ class CandidateFactory private constructor(
private fun FirExpression?.isCandidateFromCompanionObjectTypeScope(useSiteSession: FirSession): Boolean {
val resolvedQualifier = this as? FirResolvedQualifier ?: return false
val originClassOfCandidate = this.typeRef.coneType.classId ?: return false
val originClassOfCandidate = this.coneType.classId ?: return false
val companion = resolvedQualifier.symbol?.fullyExpandedClass(useSiteSession)?.fir?.companionObjectSymbol
return companion?.classId == originClassOfCandidate
}
@@ -58,7 +58,7 @@ internal object CheckExplicitReceiverConsistency : ResolutionStage() {
when (receiverKind) {
NO_EXPLICIT_RECEIVER -> {
if (explicitReceiver != null && explicitReceiver !is FirResolvedQualifier && !explicitReceiver.isSuperReferenceExpression()) {
return sink.yieldDiagnostic(InapplicableWrongReceiver(actualType = explicitReceiver.typeRef.coneTypeSafe()))
return sink.yieldDiagnostic(InapplicableWrongReceiver(actualType = explicitReceiver.coneTypeSafe()))
}
}
EXTENSION_RECEIVER, DISPATCH_RECEIVER -> {
@@ -137,7 +137,7 @@ private fun Candidate.prepareReceivers(
context: ResolutionContext,
): ReceiverDescription {
val argumentType = captureFromTypeParameterUpperBoundIfNeeded(
argumentType = argumentExtensionReceiver.typeRef.coneType,
argumentType = argumentExtensionReceiver.coneType,
expectedType = expectedType,
session = context.session
).let { prepareCapturedType(it, context) }
@@ -160,7 +160,7 @@ object CheckDispatchReceiver : ResolutionStage() {
}
}
val dispatchReceiverValueType = candidate.dispatchReceiver?.typeRef?.coneType ?: return
val dispatchReceiverValueType = candidate.dispatchReceiver?.coneType ?: return
val isReceiverNullable = !AbstractNullabilityChecker.isSubtypeOfAny(context.session.typeContext, dispatchReceiverValueType)
val isCandidateFromUnstableSmartcast =
@@ -187,7 +187,7 @@ object CheckDispatchReceiver : ResolutionStage() {
UnstableSmartCast(
smartcastedReceiver,
targetType,
context.session.typeContext.isTypeMismatchDueToNullability(smartcastedReceiver.originalExpression.typeRef.coneType, targetType)
context.session.typeContext.isTypeMismatchDueToNullability(smartcastedReceiver.originalExpression.coneType, targetType)
)
)
} else if (isReceiverNullable) {
@@ -269,7 +269,7 @@ object CheckDslScopeViolation : ResolutionStage() {
candidate,
sink,
context,
{ getDslMarkersOfImplicitReceiver(thisReference.boundSymbol, receiver.typeRef.coneType, context) }
{ getDslMarkersOfImplicitReceiver(thisReference.boundSymbol, receiver.coneType, context) }
) {
// Here we rely on the fact that receiver expression of implicit receiver value can not be changed
// during resolution of one single call
@@ -307,7 +307,7 @@ object CheckDslScopeViolation : ResolutionStage() {
// ```
// `useX()` is a call to `invoke` with `useX` as the dispatch receiver. In the FIR tree, extension receiver is represented as an
// implicit `this` expression passed as the first argument.
if (candidate.dispatchReceiver?.typeRef?.coneType?.fullyExpandedType(context.session)?.isSomeFunctionType(context.session) == true &&
if (candidate.dispatchReceiver?.coneType?.fullyExpandedType(context.session)?.isSomeFunctionType(context.session) == true &&
(candidate.symbol as? FirNamedFunctionSymbol)?.name == OperatorNameConventions.INVOKE
) {
val firstArg = candidate.argumentMapping?.keys?.firstOrNull() as? FirThisReceiverExpression ?: return
@@ -376,7 +376,7 @@ object CheckDslScopeViolation : ResolutionStage() {
private fun FirThisReceiverExpression.getDslMarkersOfThisReceiverExpression(context: ResolutionContext): Set<ClassId> {
return buildSet {
collectDslMarkerAnnotations(context, typeRef.coneType)
collectDslMarkerAnnotations(context, coneType)
}
}
@@ -713,7 +713,7 @@ internal object ProcessDynamicExtensionAnnotation : ResolutionStage() {
override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) {
if (candidate.symbol.origin === FirDeclarationOrigin.DynamicScope) return
val extensionReceiver = candidate.chosenExtensionReceiver ?: return
val argumentIsDynamic = extensionReceiver.typeRef.coneType is ConeDynamicType
val argumentIsDynamic = extensionReceiver.coneType is ConeDynamicType
val parameterIsDynamic = (candidate.symbol as? FirCallableSymbol)?.resolvedReceiverTypeRef?.type is ConeDynamicType
if (parameterIsDynamic != argumentIsDynamic ||
parameterIsDynamic && !candidate.symbol.hasAnnotation(DYNAMIC_EXTENSION_ANNOTATION_CLASS_ID, context.session)
@@ -728,7 +728,7 @@ internal object LowerPriorityIfDynamic : ResolutionStage() {
when {
candidate.symbol.origin is FirDeclarationOrigin.DynamicScope ->
candidate.addDiagnostic(LowerPriorityForDynamic)
candidate.callInfo.isImplicitInvoke && candidate.callInfo.explicitReceiver?.typeRef?.coneTypeSafe<ConeDynamicType>() != null ->
candidate.callInfo.isImplicitInvoke && candidate.callInfo.explicitReceiver?.coneTypeSafe<ConeDynamicType>() != null ->
candidate.addDiagnostic(LowerPriorityForDynamic)
}
}
@@ -85,11 +85,11 @@ private fun removeSmartCastTypeForAttemptToFitVisibility(dispatchReceiver: FirEx
val expressionWithSmartcastIfStable =
(dispatchReceiver as? FirSmartCastExpression)?.takeIf { it.isStable } ?: return null
val receiverType = dispatchReceiver.typeRef.coneType
val receiverType = dispatchReceiver.coneType
if (receiverType.isNullableNothing) return null
val originalExpression = expressionWithSmartcastIfStable.originalExpression
val originalType = originalExpression.typeRef.coneType
val originalType = originalExpression.coneType
val originalTypeNotNullable =
originalType.makeConeTypeDefinitelyNotNullOrNotNull(session.typeContext)
@@ -86,7 +86,7 @@ class MemberScopeTowerLevel(
val scope = dispatchReceiverValue.scope(session, scopeSession) ?: return ProcessResult.SCOPE_EMPTY
var (empty, candidates) = scope.collectCandidates(processScopeMembers)
val scopeWithoutSmartcast = getOriginalReceiverExpressionIfStableSmartCast()?.typeRef
val scopeWithoutSmartcast = getOriginalReceiverExpressionIfStableSmartCast()
?.coneType
?.scope(
session,
@@ -384,7 +384,7 @@ class ScopeTowerLevel(
)
return givenExtensionReceiverOptions.none { extensionReceiver ->
val extensionReceiverType = extensionReceiver.resultType.coneType
val extensionReceiverType = extensionReceiver.coneType
// If some receiver is non class like, we should not skip it
if (extensionReceiverType !is ConeClassLikeType) return@none true
@@ -970,7 +970,7 @@ abstract class FirDataFlowAnalyzer(
if (isAssignment) {
// `propertyVariable` can be an alias to `initializerVariable`, in which case this will add
// a redundant type statement which is fine...probably
flow.addTypeStatement(flow.unwrapVariable(propertyVariable) typeEq initializer.typeRef.coneType)
flow.addTypeStatement(flow.unwrapVariable(propertyVariable) typeEq initializer.coneType)
}
}
@@ -1304,7 +1304,7 @@ class ControlFlowGraphBuilder {
}
val lhsIsNotNullNode = createElvisLhsIsNotNullNode(elvisExpression).also {
val lhsIsNull = elvisExpression.lhs.typeRef.coneTypeSafe<ConeKotlinType>()?.isNullableNothing == true
val lhsIsNull = elvisExpression.lhs.coneTypeSafe<ConeKotlinType>()?.isNullableNothing == true
addEdge(lhsExitNode, it, isDead = lhsIsNull)
addEdge(it, exitNode, propagateDeadness = false)
}
@@ -78,8 +78,8 @@ class FirBuilderInferenceSession(
val dispatchReceiver = dispatchReceiver
return when {
extensionReceiver == null && dispatchReceiver == null -> false
dispatchReceiver?.typeRef?.coneType?.containsStubType() == true -> true
extensionReceiver?.typeRef?.coneType?.containsStubType() == true -> symbol.fir.hasBuilderInferenceAnnotation(session)
dispatchReceiver?.coneType?.containsStubType() == true -> true
extensionReceiver?.coneType?.containsStubType() == true -> symbol.fir.hasBuilderInferenceAnnotation(session)
else -> false
}
}
@@ -72,8 +72,8 @@ class FirDelegatedPropertyInferenceSession(
if (callee.candidate.system.hasContradiction) return true
val hasStubType =
callee.candidate.chosenExtensionReceiver?.typeRef?.coneType?.containsStubType() ?: false
|| callee.candidate.dispatchReceiver?.typeRef?.coneType?.containsStubType() ?: false
callee.candidate.chosenExtensionReceiver?.coneType?.containsStubType() ?: false
|| callee.candidate.dispatchReceiver?.coneType?.containsStubType() ?: false
if (!hasStubType) {
return true
@@ -411,7 +411,7 @@ class FirCallCompletionResultsWriterTransformer(
qualifiedAccessExpression: FirQualifiedAccessExpression,
data: Any?
): FirStatement {
val originalType = qualifiedAccessExpression.typeRef.coneType
val originalType = qualifiedAccessExpression.coneType
val substitutedReceiverType = finallySubstituteOrNull(originalType) ?: return qualifiedAccessExpression
val resolvedTypeRef = qualifiedAccessExpression.typeRef.resolvedTypeFromPrototype(substitutedReceiverType)
qualifiedAccessExpression.replaceTypeRef(resolvedTypeRef)
@@ -588,7 +588,7 @@ class FirCallCompletionResultsWriterTransformer(
// Prefer the expected type over the inferred one - the latter is a subtype of the former in valid code,
// and there will be ARGUMENT_TYPE_MISMATCH errors on the lambda's return expressions in invalid code.
val resultReturnType = expectedReturnType
?: session.typeContext.commonSuperTypeOrNull(returnExpressions.map { it.resultType.coneType })
?: session.typeContext.commonSuperTypeOrNull(returnExpressions.map { it.coneType })
?: session.builtinTypes.unitType.type
if (initialReturnType != resultReturnType) {
@@ -649,7 +649,7 @@ class FirCallCompletionResultsWriterTransformer(
}
override fun transformBlock(block: FirBlock, data: ExpectedArgumentType?): FirStatement {
val initialType = block.resultType.coneTypeSafe<ConeKotlinType>()
val initialType = block.coneTypeSafe<ConeKotlinType>()
if (initialType != null) {
val finalType = finallySubstituteOrNull(initialType)
var resultType = block.resultType.withReplacedConeType(finalType)
@@ -721,7 +721,7 @@ class FirCallCompletionResultsWriterTransformer(
syntheticCall: D,
data: ExpectedArgumentType?
) where D : FirResolvable, D : FirExpression {
val newData = data?.getExpectedType(syntheticCall)?.toExpectedType() ?: syntheticCall.typeRef.coneType.toExpectedType()
val newData = data?.getExpectedType(syntheticCall)?.toExpectedType() ?: syntheticCall.coneType.toExpectedType()
if (syntheticCall is FirTryExpression) {
syntheticCall.transformCalleeReference(this, newData)
@@ -766,7 +766,7 @@ class FirCallCompletionResultsWriterTransformer(
val expectedArrayElementType = expectedArrayType?.arrayElementType()
arrayLiteral.transformChildren(this, expectedArrayElementType?.toExpectedType())
val arrayElementType =
session.typeContext.commonSuperTypeOrNull(arrayLiteral.arguments.map { it.typeRef.coneType })?.let {
session.typeContext.commonSuperTypeOrNull(arrayLiteral.arguments.map { it.coneType })?.let {
typeApproximator.approximateToSuperType(it, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference)
?: it
} ?: expectedArrayElementType ?: session.builtinTypes.nullableAnyType.type
@@ -48,7 +48,7 @@ class FirWhenExhaustivenessTransformer(private val bodyResolveComponents: BodyRe
private fun getSubjectType(session: FirSession, whenExpression: FirWhenExpression): ConeKotlinType? {
val subjectType = whenExpression.subjectVariable?.returnTypeRef?.coneType
?: whenExpression.subject?.typeRef?.coneType
?: whenExpression.subject?.coneType
?: return null
return subjectType.fullyExpandedType(session).lowerBoundIfFlexible()
@@ -62,7 +62,7 @@ class IntegerLiteralAndOperatorApproximationTransformer(
constExpression: FirConstExpression<T>,
data: ConeKotlinType?
): FirStatement {
val type = constExpression.resultType.coneTypeSafe<ConeIntegerLiteralType>() ?: return constExpression
val type = constExpression.coneTypeSafe<ConeIntegerLiteralType>() ?: return constExpression
val approximatedType = type.getApproximatedType(data?.fullyExpandedType(session))
constExpression.resultType = constExpression.resultType.resolvedTypeFromPrototype(approximatedType)
@Suppress("UNCHECKED_CAST")
@@ -77,7 +77,7 @@ class IntegerLiteralAndOperatorApproximationTransformer(
): FirStatement {
@Suppress("UnnecessaryVariable")
val call = integerLiteralOperatorCall
val operatorType = call.resultType.coneTypeSafe<ConeIntegerLiteralType>() ?: return call
val operatorType = call.coneTypeSafe<ConeIntegerLiteralType>() ?: return call
val approximatedType = operatorType.getApproximatedType(data?.fullyExpandedType(session))
call.transformDispatchReceiver(this, null)
call.transformExtensionReceiver(this, null)
@@ -62,7 +62,7 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirAbstractBodyRes
return context.withWhenExpression(whenExpression, session) with@{
@Suppress("NAME_SHADOWING")
var whenExpression = whenExpression.transformSubject(transformer, ResolutionMode.ContextIndependent)
val subjectType = whenExpression.subject?.typeRef?.coneType?.fullyExpandedType(session)
val subjectType = whenExpression.subject?.coneType?.fullyExpandedType(session)
var completionNeeded = false
context.withWhenSubjectType(subjectType, components) {
when {
@@ -261,8 +261,8 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirAbstractBodyRes
)
var isLhsNotNull = false
if (result.rhs.typeRef.coneTypeSafe<ConeKotlinType>()?.isNothing == true) {
val lhsType = result.lhs.typeRef.coneTypeSafe<ConeKotlinType>()
if (result.rhs.coneTypeSafe<ConeKotlinType>()?.isNothing == true) {
val lhsType = result.lhs.coneTypeSafe<ConeKotlinType>()
if (lhsType != null) {
// Converting to non-raw type is necessary to preserver the K1 semantics (see KT-54526)
val newReturnType =
@@ -274,13 +274,13 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirAbstractBodyRes
}
session.typeContext.run {
if (result.typeRef.coneTypeSafe<ConeKotlinType>()?.isNullableType() == true
&& result.rhs.typeRef.coneTypeSafe<ConeKotlinType>()?.isNullableType() == false
if (result.coneTypeSafe<ConeKotlinType>()?.isNullableType() == true
&& result.rhs.coneTypeSafe<ConeKotlinType>()?.isNullableType() == false
) {
// Sometimes return type for special call for elvis operator might be nullable,
// but result is not nullable if the right type is not nullable
result.replaceTypeRef(
result.typeRef.withReplacedConeType(result.typeRef.coneType.makeConeTypeDefinitelyNotNullOrNotNull(session.typeContext))
result.typeRef.withReplacedConeType(result.coneType.makeConeTypeDefinitelyNotNullOrNotNull(session.typeContext))
)
}
}
@@ -880,7 +880,7 @@ open class FirDeclarationsResolveTransformer(
// In correct code this doesn't matter, as all return expression types should be subtypes of the expected type.
// In incorrect code, this would change diagnostics: we can get errors either on the entire lambda, or only on its
// return statements. The former kind of makes more sense, but the latter is more readable.
val inferredFromReturnExpressions = session.typeContext.commonSuperTypeOrNull(returnExpressions.map { it.expression.resultType.coneType })
val inferredFromReturnExpressions = session.typeContext.commonSuperTypeOrNull(returnExpressions.map { it.expression.coneType })
return inferredFromReturnExpressions?.let { returnTypeRef.resolvedTypeFromPrototype(it) }
?: session.builtinTypes.unitType // Empty lambda returns Unit
}
@@ -613,13 +613,13 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
fun operatorReturnTypeMatches(candidate: Candidate): Boolean {
// After KT-45503, non-assign flavor of operator is checked more strictly: the return type must be assignable to the variable.
val operatorCallReturnType = resolvedOperatorCall.typeRef.coneType
val operatorCallReturnType = resolvedOperatorCall.coneType
val substitutor = candidate.system.currentStorage()
.buildAbstractResultingSubstitutor(candidate.system.typeSystemContext) as ConeSubstitutor
return AbstractTypeChecker.isSubtypeOf(
session.typeContext,
substitutor.substituteOrSelf(operatorCallReturnType),
leftArgument.typeRef.coneType
leftArgument.coneType
)
}
// following `!!` is safe since `operatorIsSuccessful = true` implies `operatorCallReference != null`
@@ -700,7 +700,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
!assignIsSuccessful && !operatorIsSuccessful -> chooseResolved()
!assignIsSuccessful && operatorIsSuccessful -> chooseOperator()
assignIsSuccessful && !operatorIsSuccessful -> chooseAssign()
leftArgument.typeRef.coneType is ConeDynamicType -> chooseAssign()
leftArgument.coneType is ConeDynamicType -> chooseAssign()
!operatorReturnTypeMatches -> chooseAssign()
else -> reportAmbiguity()
}
@@ -845,7 +845,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
val firClass = type.lookupTag.toSymbol(session)?.fir ?: return this
if (firClass.typeParameters.isEmpty()) return this
val originalType = argument.unwrapSmartcastExpression().typeRef.coneTypeSafe<ConeKotlinType>() ?: return this
val originalType = argument.unwrapSmartcastExpression().coneTypeSafe<ConeKotlinType>() ?: return this
val newType = components.computeRepresentativeTypeForBareType(type, originalType)
?: if (firClass.isLocal && (operation == FirOperation.AS || operation == FirOperation.SAFE_AS)) {
(firClass as FirClass).defaultType()
@@ -1133,7 +1133,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
)
coneType
} else {
lhs.resultType.coneType
lhs.coneType
}
}
is FirResolvedReifiedParameterReference -> {
@@ -1208,7 +1208,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
dataFlowAnalyzer.exitConstExpression(constExpression as FirConstExpression<*>)
constExpression.resultType = constExpression.resultType.resolvedTypeFromPrototype(type)
return when (val resolvedType = constExpression.resultType.coneType) {
return when (val resolvedType = constExpression.coneType) {
is ConeErrorType -> buildErrorExpression {
expression = constExpression
diagnostic = resolvedType.diagnostic
@@ -1306,7 +1306,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
.resolveDelegatingConstructorCall(delegatedConstructorCall, constructorType, containingClass.symbol.toLookupTag())
if (reference is FirThisReference && reference.boundSymbol == null) {
resolvedCall.dispatchReceiver.typeRef.coneTypeSafe<ConeClassLikeType>()?.lookupTag?.toSymbol(session)?.let {
resolvedCall.dispatchReceiver.coneTypeSafe<ConeClassLikeType>()?.lookupTag?.toSymbol(session)?.let {
reference.replaceBoundSymbol(it)
}
}
@@ -194,7 +194,7 @@ class ConeEffectExtractor(
val ownerHasReceiver = callableOwner?.receiverParameter != null
val ownerIsMemberOfDeclaration = callableOwner?.getContainingClass(session) == declaration
return if (declaration == owner || owner.isAccessorOf(declaration) || ownerIsMemberOfDeclaration && !ownerHasReceiver) {
val type = thisReceiverExpression.typeRef.coneType
val type = thisReceiverExpression.coneType
toValueParameterReference(type, -1, "this")
} else {
ConeContractDescriptionError.IllegalThis(thisReceiverExpression).asElement()
@@ -354,7 +354,7 @@ class FirExpectActualMatchingContextImpl private constructor(
}
private fun areFirAnnotationsEqual(annotation1: FirAnnotation, annotation2: FirAnnotation): Boolean {
if (!areCompatibleExpectActualTypes(annotation1.typeRef.coneType, annotation2.typeRef.coneType)) {
if (!areCompatibleExpectActualTypes(annotation1.coneType, annotation2.coneType)) {
return false
}
val args1 = annotation1.argumentMapping.mapping
@@ -176,7 +176,7 @@ class VariableStorageImpl(private val session: FirSession) : VariableStorage() {
property.visibility == Visibilities.Private -> PropertyStability.STABLE_VALUE
property.modality != Modality.FINAL -> {
val dispatchReceiver = (originalFir.unwrapElement() as? FirQualifiedAccessExpression)?.dispatchReceiver ?: return null
val receiverType = dispatchReceiver.typeRef.coneTypeSafe<ConeClassLikeType>()?.fullyExpandedType(session) ?: return null
val receiverType = dispatchReceiver.coneTypeSafe<ConeClassLikeType>()?.fullyExpandedType(session) ?: return null
val receiverSymbol = receiverType.lookupTag.toSymbol(session) ?: return null
when (val receiverFir = receiverSymbol.fir) {
is FirAnonymousObject -> PropertyStability.STABLE_VALUE
@@ -895,7 +895,7 @@ class FakeExpressionEnterNode(owner: ControlFlowGraph, level: Int) : CFGNode<Fir
class SmartCastExpressionExitNode(owner: ControlFlowGraph, override val fir: FirSmartCastExpression, level: Int) : CFGNode<FirSmartCastExpression>(owner, level) {
override val canThrow: Boolean
get() = fir.typeRef.coneType.isNothing
get() = fir.coneType.isNothing
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
return visitor.visitSmartCastExpressionExitNode(this, data)
@@ -36,10 +36,6 @@ fun FirOperation.isEq(): Boolean {
}
}
@DfaInternals
val FirExpression.coneType: ConeKotlinType
get() = typeRef.coneType
@DfaInternals
val FirElement.symbol: FirBasedSymbol<*>?
get() = when (this) {
@@ -57,7 +57,7 @@ fun computePublishedApiEffectiveVisibility(
session: FirSession,
): EffectiveVisibility? {
val hasPublishedApiAnnotation = annotations.any {
it.typeRef.coneTypeSafe<ConeClassLikeType>()?.lookupTag?.classId == StandardClassIds.Annotations.PublishedApi
it.coneTypeSafe<ConeClassLikeType>()?.lookupTag?.classId == StandardClassIds.Annotations.PublishedApi
}
return computePublishedApiEffectiveVisibility(
@@ -142,4 +142,4 @@ fun FirMemberDeclaration.setLazyPublishedVisibility(hasPublishedApi: Boolean, pa
session = session,
)
}
}
}

Some files were not shown because too many files have changed in this diff Show More