Fix all illegal usages of safeAs function
Call of `safeAs` without specifying explicit type argument is hardly readable and may leads to hardly detectable errors
This commit is contained in:
@@ -127,7 +127,7 @@ fun FirTypeRef.toRegularClass(session: FirSession): FirRegularClass? {
|
||||
inline fun <reified T : Any> FirQualifiedAccessExpression.getDeclaration(): T? {
|
||||
return this.calleeReference.safeAs<FirResolvedNamedReference>()
|
||||
?.resolvedSymbol
|
||||
?.fir.safeAs()
|
||||
?.fir as? T
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -94,5 +94,5 @@ object FirCommonConstructorDelegationIssuesChecker : FirRegularClassChecker() {
|
||||
private fun FirConstructor.getDelegated(): FirConstructor? = delegatedConstructor
|
||||
?.calleeReference.safeAs<FirResolvedNamedReference>()
|
||||
?.resolvedSymbol
|
||||
?.fir.safeAs()
|
||||
?.fir as? FirConstructor?
|
||||
}
|
||||
|
||||
+2
-2
@@ -108,7 +108,7 @@ object FirOverrideChecker : FirClassChecker() {
|
||||
overriddenSymbols: List<FirCallableSymbol<*>>,
|
||||
): FirMemberDeclaration? {
|
||||
if (isVar) return null
|
||||
return overriddenSymbols.find { (it.fir as? FirProperty)?.isVar == true }?.fir?.safeAs()
|
||||
return overriddenSymbols.find { (it.fir as? FirProperty)?.isVar == true }?.fir as? FirMemberDeclaration?
|
||||
}
|
||||
|
||||
private fun FirCallableMemberDeclaration.checkVisibility(
|
||||
@@ -178,7 +178,7 @@ object FirOverrideChecker : FirClassChecker() {
|
||||
AbstractTypeChecker.isSubtypeOf(typeCheckerContext, overridingReturnType, overriddenReturnType)
|
||||
|
||||
if (!isReturnTypeOkForOverride) {
|
||||
return overriddenDeclaration.safeAs()
|
||||
return overriddenDeclaration as? FirMemberDeclaration
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ object FirUpperBoundViolatedExpressionChecker : FirQualifiedAccessExpressionChec
|
||||
val calleReference = expression.calleeReference
|
||||
var calleeFir: FirTypeParameterRefsOwner? = null
|
||||
if (calleReference is FirResolvedNamedReference) {
|
||||
calleeFir = calleReference.safeAs<FirResolvedNamedReference>()?.resolvedSymbol?.fir.safeAs()
|
||||
calleeFir = calleReference.safeAs<FirResolvedNamedReference>()?.resolvedSymbol?.fir as? FirTypeParameterRefsOwner
|
||||
} else if (calleReference is FirErrorNamedReference) {
|
||||
val diagnostic = calleReference.diagnostic
|
||||
if (diagnostic is ConeInapplicableCandidateError &&
|
||||
@@ -37,7 +37,7 @@ object FirUpperBoundViolatedExpressionChecker : FirQualifiedAccessExpressionChec
|
||||
) {
|
||||
return
|
||||
}
|
||||
calleeFir = calleReference.candidateSymbol?.fir.safeAs()
|
||||
calleeFir = calleReference.candidateSymbol?.fir as? FirTypeParameterRefsOwner
|
||||
}
|
||||
|
||||
var typeArguments: List<Any>? = null
|
||||
@@ -61,4 +61,4 @@ object FirUpperBoundViolatedExpressionChecker : FirQualifiedAccessExpressionChec
|
||||
typeArgumentRefsAndSources
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ private fun ConeDiagnostic.toFirDiagnostic(
|
||||
is FirBackingFieldSymbol -> FirErrors.VAL_REASSIGNMENT_VIA_BACKING_FIELD_ERROR.createOn(source, symbol.fir.symbol)
|
||||
else -> FirErrors.VAL_REASSIGNMENT.createOn(source, symbol)
|
||||
}
|
||||
is ConeUnexpectedTypeArgumentsError -> FirErrors.TYPE_ARGUMENTS_NOT_ALLOWED.createOn(this.source.safeAs() ?: source)
|
||||
is ConeUnexpectedTypeArgumentsError -> FirErrors.TYPE_ARGUMENTS_NOT_ALLOWED.createOn(this.source as? FirSourceElement ?: source)
|
||||
is ConeIllegalAnnotationError -> FirErrors.NOT_AN_ANNOTATION_CLASS.createOn(source, this.name.asString())
|
||||
is ConeWrongNumberOfTypeArgumentsError ->
|
||||
FirErrors.WRONG_NUMBER_OF_TYPE_ARGUMENTS.createOn(qualifiedAccessSource ?: source, this.desiredCount, this.type)
|
||||
|
||||
@@ -88,7 +88,7 @@ private fun <T : FirAnnotatedDeclaration> T.getDeprecationForCallSite(
|
||||
|
||||
private fun FirAnnotationCall.getStringArgument(name: Name): String? =
|
||||
findArgumentByName(name)?.let { expression ->
|
||||
expression.safeAs<FirConstExpression<*>>()?.value.safeAs()
|
||||
expression.safeAs<FirConstExpression<*>>()?.value as? String
|
||||
}
|
||||
|
||||
private fun FirAnnotationCall.getVersionFromArgument(name: Name): ApiVersion? =
|
||||
|
||||
Reference in New Issue
Block a user