[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 typeArgumentMap = mutableMapOf<FirTypeParameterSymbol, ConeKotlinType>()
|
||||
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) {
|
||||
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.FirThisReference
|
||||
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.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
@@ -301,7 +298,7 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
|
||||
}
|
||||
|
||||
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? {
|
||||
|
||||
+1
-1
@@ -265,7 +265,7 @@ object ConeTypeCompatibilityChecker {
|
||||
|
||||
private fun FirTypeParameterSymbol?.collectUpperBounds(): Set<ConeClassLikeType> {
|
||||
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> {
|
||||
|
||||
@@ -515,9 +515,8 @@ fun checkTypeMismatch(
|
||||
}
|
||||
|
||||
internal fun checkCondition(condition: FirExpression, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val coneType = condition.typeRef.coneTypeSafe<ConeKotlinType>()?.lowerBoundIfFlexible()
|
||||
if (coneType != null &&
|
||||
coneType !is ConeErrorType &&
|
||||
val coneType = condition.typeRef.coneType.lowerBoundIfFlexible()
|
||||
if (coneType !is ConeErrorType &&
|
||||
!coneType.isSubtypeOf(context.session.typeContext, context.session.builtinTypes.booleanType.type)
|
||||
) {
|
||||
reporter.reportOn(
|
||||
@@ -588,8 +587,7 @@ fun FirFunctionSymbol<*>.isFunctionForExpectTypeFromCastFeature(): Boolean {
|
||||
if ((returnType.lowerBoundIfFlexible() as? ConeTypeParameterType)?.lookupTag != typeParameterSymbol.toLookupTag()) return false
|
||||
|
||||
fun FirTypeRef.isBadType() =
|
||||
coneTypeSafe<ConeKotlinType>()
|
||||
?.contains { (it.lowerBoundIfFlexible() as? ConeTypeParameterType)?.lookupTag == typeParameterSymbol.toLookupTag() } != false
|
||||
coneType.contains { (it.lowerBoundIfFlexible() as? ConeTypeParameterType)?.lookupTag == typeParameterSymbol.toLookupTag() }
|
||||
|
||||
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 (declaration !is FirConstructor && declaration !is FirPropertyAccessor) {
|
||||
declaration.returnTypeRef.coneTypeSafe<ConeKotlinType>()
|
||||
?.findVisibilityExposure(context, functionVisibility)?.let { (restricting, restrictingVisibility) ->
|
||||
declaration.returnTypeRef.coneType
|
||||
.findVisibilityExposure(context, functionVisibility)?.let { (restricting, restrictingVisibility) ->
|
||||
reporter.reportOn(
|
||||
declaration.source,
|
||||
FirErrors.EXPOSED_FUNCTION_RETURN_TYPE,
|
||||
@@ -128,8 +128,8 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() {
|
||||
if (declaration !is FirPropertyAccessor) {
|
||||
declaration.valueParameters.forEachIndexed { i, valueParameter ->
|
||||
if (i < declaration.valueParameters.size) {
|
||||
val (restricting, restrictingVisibility) = valueParameter.returnTypeRef.coneTypeSafe<ConeKotlinType>()
|
||||
?.findVisibilityExposure(context, functionVisibility) ?: return@forEachIndexed
|
||||
val (restricting, restrictingVisibility) = valueParameter.returnTypeRef.coneType
|
||||
.findVisibilityExposure(context, functionVisibility) ?: return@forEachIndexed
|
||||
reporter.reportOn(
|
||||
valueParameter.source,
|
||||
FirErrors.EXPOSED_PARAMETER_TYPE,
|
||||
@@ -149,8 +149,8 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() {
|
||||
val propertyVisibility = declaration.effectiveVisibility
|
||||
|
||||
if (propertyVisibility == EffectiveVisibility.Local) return
|
||||
declaration.returnTypeRef.coneTypeSafe<ConeKotlinType>()
|
||||
?.findVisibilityExposure(context, propertyVisibility)?.let { (restricting, restrictingVisibility) ->
|
||||
declaration.returnTypeRef.coneType
|
||||
.findVisibilityExposure(context, propertyVisibility)?.let { (restricting, restrictingVisibility) ->
|
||||
if (declaration.fromPrimaryConstructor == true) {
|
||||
reporter.reportOn(
|
||||
declaration.source,
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() {
|
||||
else
|
||||
targetElement.returnTypeRef.coneType
|
||||
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 (resultExpression.isNullLiteral && functionReturnType.nullability == ConeNullability.NOT_NULL) {
|
||||
|
||||
+1
-1
@@ -157,7 +157,7 @@ object FirOptInUsageBaseChecker {
|
||||
}
|
||||
if (fir !is FirConstructor) {
|
||||
// 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)
|
||||
if (fir is FirSimpleFunction) {
|
||||
fir.valueParameters.forEach {
|
||||
|
||||
+1
-1
@@ -223,7 +223,7 @@ object FirSuspendCallChecker : FirQualifiedAccessExpressionChecker() {
|
||||
calledDeclarationSymbol: FirCallableSymbol<*>
|
||||
): Triple<FirExpression?, FirExpression?, ConeKotlinType?> {
|
||||
if (this is FirImplicitInvokeCall &&
|
||||
dispatchReceiver.typeRef.coneTypeSafe<ConeKotlinType>()?.isSuspendFunctionType(session) == true
|
||||
dispatchReceiver != FirNoReceiverExpression && dispatchReceiver.typeRef.coneType.isSuspendFunctionType(session)
|
||||
) {
|
||||
val variableForInvoke = dispatchReceiver
|
||||
val variableForInvokeType = variableForInvoke.typeRef.coneType
|
||||
|
||||
+1
-1
@@ -235,7 +235,7 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
||||
withLabelAndReceiverType(
|
||||
labelName,
|
||||
declaration,
|
||||
receiverTypeRef?.coneTypeSafe()
|
||||
receiverTypeRef?.coneType
|
||||
) {
|
||||
visitNestedElements(declaration)
|
||||
}
|
||||
|
||||
+1
-2
@@ -745,8 +745,7 @@ class CallAndReferenceGenerator(
|
||||
val map = mutableMapOf<FirTypeParameterSymbol, ConeKotlinType>()
|
||||
for ((index, typeParameter) in function.typeParameters.withIndex()) {
|
||||
val typeProjection = typeArguments.getOrNull(index) as? FirTypeProjectionWithVariance ?: continue
|
||||
val type = typeProjection.typeRef.coneTypeSafe<ConeKotlinType>() ?: continue
|
||||
map[typeParameter.symbol] = type
|
||||
map[typeParameter.symbol] = typeProjection.typeRef.coneType
|
||||
}
|
||||
return ConeSubstitutorByMap(map, session)
|
||||
}
|
||||
|
||||
@@ -179,8 +179,7 @@ private fun ConeTypeParameterType.hasNotNullUpperBound(): Boolean {
|
||||
}
|
||||
|
||||
val FirTypeRef.canBeNull: Boolean
|
||||
// TODO: replace with coneType (for some reason, implicit type still can arise here)
|
||||
get() = coneTypeSafe<ConeKotlinType>()?.canBeNull == true
|
||||
get() = coneType.canBeNull
|
||||
|
||||
val ConeKotlinType.canBeNull: Boolean
|
||||
get() {
|
||||
|
||||
Reference in New Issue
Block a user