[FIR] Use coneType instead of coneTypeSafe<ConeKotlinType> in checkers and fir2ir
This commit is contained in:
+1
-1
@@ -55,7 +55,7 @@ object FirJavaGenericVarianceViolationTypeChecker : FirFunctionCallChecker() {
|
|||||||
val argumentMapping = expression.argumentMapping ?: return
|
val argumentMapping = expression.argumentMapping ?: return
|
||||||
val typeArgumentMap = mutableMapOf<FirTypeParameterSymbol, ConeKotlinType>()
|
val typeArgumentMap = mutableMapOf<FirTypeParameterSymbol, ConeKotlinType>()
|
||||||
for (i in 0 until expression.typeArguments.size) {
|
for (i in 0 until expression.typeArguments.size) {
|
||||||
val type = expression.typeArguments[i].safeAs<FirTypeProjectionWithVariance>()?.typeRef?.coneTypeSafe<ConeKotlinType>()
|
val type = expression.typeArguments[i].safeAs<FirTypeProjectionWithVariance>()?.typeRef?.coneType
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
typeArgumentMap[calleeFunction.typeParameterSymbols[i]] = type
|
typeArgumentMap[calleeFunction.typeParameterSymbols[i]] = type
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-5
@@ -31,13 +31,10 @@ import org.jetbrains.kotlin.fir.references.FirReference
|
|||||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||||
import org.jetbrains.kotlin.fir.references.FirThisReference
|
import org.jetbrains.kotlin.fir.references.FirThisReference
|
||||||
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.*
|
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.*
|
||||||
import org.jetbrains.kotlin.fir.types.isBuiltinFunctionalType
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.isInvoke
|
import org.jetbrains.kotlin.fir.resolve.isInvoke
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
|
||||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
import kotlin.contracts.ExperimentalContracts
|
import kotlin.contracts.ExperimentalContracts
|
||||||
import kotlin.contracts.contract
|
import kotlin.contracts.contract
|
||||||
@@ -301,7 +298,7 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun FirTypeRef?.isFunctionalTypeRef(session: FirSession): Boolean {
|
private fun FirTypeRef?.isFunctionalTypeRef(session: FirSession): Boolean {
|
||||||
return this?.coneTypeSafe<ConeKotlinType>()?.isBuiltinFunctionalType(session) == true
|
return this?.coneType?.isBuiltinFunctionalType(session) == true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FirContractDescription?.getParameterCallsEffectDeclaration(index: Int): ConeCallsEffectDeclaration? {
|
private fun FirContractDescription?.getParameterCallsEffectDeclaration(index: Int): ConeCallsEffectDeclaration? {
|
||||||
|
|||||||
+1
-1
@@ -265,7 +265,7 @@ object ConeTypeCompatibilityChecker {
|
|||||||
|
|
||||||
private fun FirTypeParameterSymbol?.collectUpperBounds(): Set<ConeClassLikeType> {
|
private fun FirTypeParameterSymbol?.collectUpperBounds(): Set<ConeClassLikeType> {
|
||||||
if (this == null) return emptySet()
|
if (this == null) return emptySet()
|
||||||
return resolvedBounds.flatMap { it.coneTypeSafe<ConeKotlinType>().collectUpperBounds() }.toSet()
|
return resolvedBounds.flatMap { it.coneType.collectUpperBounds() }.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ConeKotlinType?.collectLowerBounds(): Set<ConeClassLikeType> {
|
private fun ConeKotlinType?.collectLowerBounds(): Set<ConeClassLikeType> {
|
||||||
|
|||||||
@@ -515,9 +515,8 @@ fun checkTypeMismatch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun checkCondition(condition: FirExpression, context: CheckerContext, reporter: DiagnosticReporter) {
|
internal fun checkCondition(condition: FirExpression, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
val coneType = condition.typeRef.coneTypeSafe<ConeKotlinType>()?.lowerBoundIfFlexible()
|
val coneType = condition.typeRef.coneType.lowerBoundIfFlexible()
|
||||||
if (coneType != null &&
|
if (coneType !is ConeErrorType &&
|
||||||
coneType !is ConeErrorType &&
|
|
||||||
!coneType.isSubtypeOf(context.session.typeContext, context.session.builtinTypes.booleanType.type)
|
!coneType.isSubtypeOf(context.session.typeContext, context.session.builtinTypes.booleanType.type)
|
||||||
) {
|
) {
|
||||||
reporter.reportOn(
|
reporter.reportOn(
|
||||||
@@ -588,8 +587,7 @@ fun FirFunctionSymbol<*>.isFunctionForExpectTypeFromCastFeature(): Boolean {
|
|||||||
if ((returnType.lowerBoundIfFlexible() as? ConeTypeParameterType)?.lookupTag != typeParameterSymbol.toLookupTag()) return false
|
if ((returnType.lowerBoundIfFlexible() as? ConeTypeParameterType)?.lookupTag != typeParameterSymbol.toLookupTag()) return false
|
||||||
|
|
||||||
fun FirTypeRef.isBadType() =
|
fun FirTypeRef.isBadType() =
|
||||||
coneTypeSafe<ConeKotlinType>()
|
coneType.contains { (it.lowerBoundIfFlexible() as? ConeTypeParameterType)?.lookupTag == typeParameterSymbol.toLookupTag() }
|
||||||
?.contains { (it.lowerBoundIfFlexible() as? ConeTypeParameterType)?.lookupTag == typeParameterSymbol.toLookupTag() } != false
|
|
||||||
|
|
||||||
if (valueParameterSymbols.any { it.resolvedReturnTypeRef.isBadType() } || resolvedReceiverTypeRef?.isBadType() == true) return false
|
if (valueParameterSymbols.any { it.resolvedReturnTypeRef.isBadType() } || resolvedReceiverTypeRef?.isBadType() == true) return false
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -113,8 +113,8 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() {
|
|||||||
|
|
||||||
if (functionVisibility == EffectiveVisibility.Local) return
|
if (functionVisibility == EffectiveVisibility.Local) return
|
||||||
if (declaration !is FirConstructor && declaration !is FirPropertyAccessor) {
|
if (declaration !is FirConstructor && declaration !is FirPropertyAccessor) {
|
||||||
declaration.returnTypeRef.coneTypeSafe<ConeKotlinType>()
|
declaration.returnTypeRef.coneType
|
||||||
?.findVisibilityExposure(context, functionVisibility)?.let { (restricting, restrictingVisibility) ->
|
.findVisibilityExposure(context, functionVisibility)?.let { (restricting, restrictingVisibility) ->
|
||||||
reporter.reportOn(
|
reporter.reportOn(
|
||||||
declaration.source,
|
declaration.source,
|
||||||
FirErrors.EXPOSED_FUNCTION_RETURN_TYPE,
|
FirErrors.EXPOSED_FUNCTION_RETURN_TYPE,
|
||||||
@@ -128,8 +128,8 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() {
|
|||||||
if (declaration !is FirPropertyAccessor) {
|
if (declaration !is FirPropertyAccessor) {
|
||||||
declaration.valueParameters.forEachIndexed { i, valueParameter ->
|
declaration.valueParameters.forEachIndexed { i, valueParameter ->
|
||||||
if (i < declaration.valueParameters.size) {
|
if (i < declaration.valueParameters.size) {
|
||||||
val (restricting, restrictingVisibility) = valueParameter.returnTypeRef.coneTypeSafe<ConeKotlinType>()
|
val (restricting, restrictingVisibility) = valueParameter.returnTypeRef.coneType
|
||||||
?.findVisibilityExposure(context, functionVisibility) ?: return@forEachIndexed
|
.findVisibilityExposure(context, functionVisibility) ?: return@forEachIndexed
|
||||||
reporter.reportOn(
|
reporter.reportOn(
|
||||||
valueParameter.source,
|
valueParameter.source,
|
||||||
FirErrors.EXPOSED_PARAMETER_TYPE,
|
FirErrors.EXPOSED_PARAMETER_TYPE,
|
||||||
@@ -149,8 +149,8 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() {
|
|||||||
val propertyVisibility = declaration.effectiveVisibility
|
val propertyVisibility = declaration.effectiveVisibility
|
||||||
|
|
||||||
if (propertyVisibility == EffectiveVisibility.Local) return
|
if (propertyVisibility == EffectiveVisibility.Local) return
|
||||||
declaration.returnTypeRef.coneTypeSafe<ConeKotlinType>()
|
declaration.returnTypeRef.coneType
|
||||||
?.findVisibilityExposure(context, propertyVisibility)?.let { (restricting, restrictingVisibility) ->
|
.findVisibilityExposure(context, propertyVisibility)?.let { (restricting, restrictingVisibility) ->
|
||||||
if (declaration.fromPrimaryConstructor == true) {
|
if (declaration.fromPrimaryConstructor == true) {
|
||||||
reporter.reportOn(
|
reporter.reportOn(
|
||||||
declaration.source,
|
declaration.source,
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() {
|
|||||||
else
|
else
|
||||||
targetElement.returnTypeRef.coneType
|
targetElement.returnTypeRef.coneType
|
||||||
val typeContext = context.session.typeContext
|
val typeContext = context.session.typeContext
|
||||||
val returnExpressionType = resultExpression.typeRef.coneTypeSafe<ConeKotlinType>() ?: return
|
val returnExpressionType = resultExpression.typeRef.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
@@ -157,7 +157,7 @@ object FirOptInUsageBaseChecker {
|
|||||||
}
|
}
|
||||||
if (fir !is FirConstructor) {
|
if (fir !is FirConstructor) {
|
||||||
// Without coneTypeSafe v fails in MT test (FirRenderer.kt)
|
// Without coneTypeSafe v fails in MT test (FirRenderer.kt)
|
||||||
fir.returnTypeRef.coneTypeSafe<ConeKotlinType>().addExperimentalities(context, result, visited)
|
fir.returnTypeRef.coneType.addExperimentalities(context, result, visited)
|
||||||
fir.receiverTypeRef?.coneType.addExperimentalities(context, result, visited)
|
fir.receiverTypeRef?.coneType.addExperimentalities(context, result, visited)
|
||||||
if (fir is FirSimpleFunction) {
|
if (fir is FirSimpleFunction) {
|
||||||
fir.valueParameters.forEach {
|
fir.valueParameters.forEach {
|
||||||
|
|||||||
+1
-1
@@ -223,7 +223,7 @@ object FirSuspendCallChecker : FirQualifiedAccessExpressionChecker() {
|
|||||||
calledDeclarationSymbol: FirCallableSymbol<*>
|
calledDeclarationSymbol: FirCallableSymbol<*>
|
||||||
): Triple<FirExpression?, FirExpression?, ConeKotlinType?> {
|
): Triple<FirExpression?, FirExpression?, ConeKotlinType?> {
|
||||||
if (this is FirImplicitInvokeCall &&
|
if (this is FirImplicitInvokeCall &&
|
||||||
dispatchReceiver.typeRef.coneTypeSafe<ConeKotlinType>()?.isSuspendFunctionType(session) == true
|
dispatchReceiver != FirNoReceiverExpression && dispatchReceiver.typeRef.coneType.isSuspendFunctionType(session)
|
||||||
) {
|
) {
|
||||||
val variableForInvoke = dispatchReceiver
|
val variableForInvoke = dispatchReceiver
|
||||||
val variableForInvokeType = variableForInvoke.typeRef.coneType
|
val variableForInvokeType = variableForInvoke.typeRef.coneType
|
||||||
|
|||||||
+1
-1
@@ -235,7 +235,7 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
|||||||
withLabelAndReceiverType(
|
withLabelAndReceiverType(
|
||||||
labelName,
|
labelName,
|
||||||
declaration,
|
declaration,
|
||||||
receiverTypeRef?.coneTypeSafe()
|
receiverTypeRef?.coneType
|
||||||
) {
|
) {
|
||||||
visitNestedElements(declaration)
|
visitNestedElements(declaration)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -745,8 +745,7 @@ class CallAndReferenceGenerator(
|
|||||||
val map = mutableMapOf<FirTypeParameterSymbol, ConeKotlinType>()
|
val map = mutableMapOf<FirTypeParameterSymbol, ConeKotlinType>()
|
||||||
for ((index, typeParameter) in function.typeParameters.withIndex()) {
|
for ((index, typeParameter) in function.typeParameters.withIndex()) {
|
||||||
val typeProjection = typeArguments.getOrNull(index) as? FirTypeProjectionWithVariance ?: continue
|
val typeProjection = typeArguments.getOrNull(index) as? FirTypeProjectionWithVariance ?: continue
|
||||||
val type = typeProjection.typeRef.coneTypeSafe<ConeKotlinType>() ?: continue
|
map[typeParameter.symbol] = typeProjection.typeRef.coneType
|
||||||
map[typeParameter.symbol] = type
|
|
||||||
}
|
}
|
||||||
return ConeSubstitutorByMap(map, session)
|
return ConeSubstitutorByMap(map, session)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,8 +179,7 @@ private fun ConeTypeParameterType.hasNotNullUpperBound(): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val FirTypeRef.canBeNull: Boolean
|
val FirTypeRef.canBeNull: Boolean
|
||||||
// TODO: replace with coneType (for some reason, implicit type still can arise here)
|
get() = coneType.canBeNull
|
||||||
get() = coneTypeSafe<ConeKotlinType>()?.canBeNull == true
|
|
||||||
|
|
||||||
val ConeKotlinType.canBeNull: Boolean
|
val ConeKotlinType.canBeNull: Boolean
|
||||||
get() {
|
get() {
|
||||||
|
|||||||
Reference in New Issue
Block a user