@@ -1967,36 +1967,58 @@ void TypeChecker::checkConcurrencyAvailability(SourceRange ReferenceRange,
1967
1967
}
1968
1968
}
1969
1969
1970
+ // / Returns the diagnostic to emit for the potentially unavailable decl and sets
1971
+ // / \p IsError accordingly.
1972
+ static Diagnostic getPotentialUnavailabilityDiagnostic (
1973
+ const ValueDecl *D, const DeclContext *ReferenceDC,
1974
+ const UnavailabilityReason &Reason, bool WarnBeforeDeploymentTarget,
1975
+ bool &IsError) {
1976
+ ASTContext &Context = ReferenceDC->getASTContext ();
1977
+ auto Platform = prettyPlatformString (targetPlatform (Context.LangOpts ));
1978
+ auto Version = Reason.getRequiredOSVersionRange ().getLowerEndpoint ();
1979
+
1980
+ const bool RequiredVersionIsDeploymentTargetOrLower =
1981
+ Version <= AvailabilityContext::forDeploymentTarget (Context)
1982
+ .getOSVersion ()
1983
+ .getLowerEndpoint ();
1984
+
1985
+ if (RequiredVersionIsDeploymentTargetOrLower) {
1986
+ IsError = !WarnBeforeDeploymentTarget;
1987
+
1988
+ return Diagnostic (
1989
+ IsError ? diag::availability_decl_only_version_newer_for_clients
1990
+ : diag::availability_decl_only_version_newer_for_clients_warn,
1991
+ D->getName (), ReferenceDC->getParentModule (), Platform, Version);
1992
+ }
1993
+
1994
+ IsError = true ;
1995
+ return Diagnostic (diag::availability_decl_only_version_newer, D->getName (),
1996
+ Platform, Version);
1997
+ }
1998
+
1970
1999
bool TypeChecker::diagnosePotentialUnavailability (
1971
2000
const ValueDecl *D, SourceRange ReferenceRange,
1972
2001
const DeclContext *ReferenceDC,
1973
2002
const UnavailabilityReason &Reason,
1974
2003
bool WarnBeforeDeploymentTarget) {
1975
2004
ASTContext &Context = ReferenceDC->getASTContext ();
1976
2005
1977
- bool AsError = true ;
1978
2006
auto RequiredRange = Reason.getRequiredOSVersionRange ();
2007
+ bool IsError;
1979
2008
{
1980
- if (WarnBeforeDeploymentTarget &&
1981
- !RequiredRange.isContainedIn (
1982
- AvailabilityContext::forDeploymentTarget (Context).getOSVersion ()))
1983
- AsError = false ;
1984
-
1985
2009
auto Diag = Context.Diags .diagnose (
1986
2010
ReferenceRange.Start ,
1987
- AsError ? diag::availability_decl_only_version_newer
1988
- : diag::availability_decl_only_version_newer_warn,
1989
- D->getName (), prettyPlatformString (targetPlatform (Context.LangOpts )),
1990
- Reason.getRequiredOSVersionRange ().getLowerEndpoint ());
2011
+ getPotentialUnavailabilityDiagnostic (
2012
+ D, ReferenceDC, Reason, WarnBeforeDeploymentTarget, IsError));
1991
2013
1992
2014
// Direct a fixit to the error if an existing guard is nearly-correct
1993
2015
if (fixAvailabilityByNarrowingNearbyVersionCheck (
1994
2016
ReferenceRange, ReferenceDC, RequiredRange, Context, Diag))
1995
- return AsError ;
2017
+ return IsError ;
1996
2018
}
1997
2019
1998
2020
fixAvailability (ReferenceRange, ReferenceDC, RequiredRange, Context);
1999
- return AsError ;
2021
+ return IsError ;
2000
2022
}
2001
2023
2002
2024
void TypeChecker::diagnosePotentialAccessorUnavailability (
0 commit comments