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