@@ -1851,11 +1851,8 @@ static void fixAvailabilityForDecl(SourceRange ReferenceRange, const Decl *D,
1851
1851
// / version), emit a diagnostic and fixit that narrows the existing TRC
1852
1852
// / condition to the required range.
1853
1853
static bool fixAvailabilityByNarrowingNearbyVersionCheck (
1854
- SourceRange ReferenceRange,
1855
- const DeclContext *ReferenceDC,
1856
- const VersionRange &RequiredRange,
1857
- ASTContext &Context,
1858
- InFlightDiagnostic &Err) {
1854
+ SourceRange ReferenceRange, const DeclContext *ReferenceDC,
1855
+ const VersionRange &RequiredRange, ASTContext &Context) {
1859
1856
const TypeRefinementContext *TRC = nullptr ;
1860
1857
(void )TypeChecker::overApproximateAvailabilityAtLocation (ReferenceRange.Start ,
1861
1858
ReferenceDC, &TRC);
@@ -1889,8 +1886,13 @@ static bool fixAvailabilityByNarrowingNearbyVersionCheck(
1889
1886
Platform, RunningVers);
1890
1887
if (!FixRange.isValid ())
1891
1888
return false ;
1889
+
1892
1890
// Have found a nontrivial type refinement context-introducer to narrow.
1893
- Err.fixItReplace (FixRange, RequiredVers.getAsString ());
1891
+ Context.Diags
1892
+ .diagnose (FixRange.Start ,
1893
+ diag::availability_narrow_nearby_version_check,
1894
+ RunningVers.getAsString (), RequiredVers.getAsString ())
1895
+ .fixItReplace (FixRange, RequiredVers.getAsString ());
1894
1896
return true ;
1895
1897
}
1896
1898
return false ;
@@ -1966,14 +1968,17 @@ static void fixAvailabilityByAddingVersionCheck(
1966
1968
}
1967
1969
1968
1970
// / Emit suggested Fix-Its for a reference with to an unavailable symbol
1969
- // / requiting the given OS version range.
1971
+ // / requiring the given OS version range.
1970
1972
static void fixAvailability (SourceRange ReferenceRange,
1971
1973
const DeclContext *ReferenceDC,
1972
1974
const VersionRange &RequiredRange,
1973
1975
ASTContext &Context) {
1974
1976
if (ReferenceRange.isInvalid ())
1975
1977
return ;
1976
1978
1979
+ fixAvailabilityByNarrowingNearbyVersionCheck (ReferenceRange, ReferenceDC,
1980
+ RequiredRange, Context);
1981
+
1977
1982
Optional<ASTNode> NodeToWrapInVersionCheck;
1978
1983
const Decl *FoundMemberDecl = nullptr ;
1979
1984
const Decl *FoundTypeLevelDecl = nullptr ;
@@ -2006,19 +2011,12 @@ void TypeChecker::diagnosePotentialOpaqueTypeUnavailability(
2006
2011
ASTContext &Context = ReferenceDC->getASTContext ();
2007
2012
2008
2013
auto RequiredRange = Reason.getRequiredOSVersionRange ();
2009
- {
2010
- auto Err =
2011
- Context.Diags .diagnose (
2012
- ReferenceRange.Start , diag::availability_opaque_types_only_version_newer,
2013
- prettyPlatformString (targetPlatform (Context.LangOpts )),
2014
- Reason.getRequiredOSVersionRange ().getLowerEndpoint ());
2015
-
2016
- // Direct a fixit to the error if an existing guard is nearly-correct
2017
- if (fixAvailabilityByNarrowingNearbyVersionCheck (ReferenceRange,
2018
- ReferenceDC,
2019
- RequiredRange, Context, Err))
2020
- return ;
2021
- }
2014
+
2015
+ Context.Diags .diagnose (ReferenceRange.Start ,
2016
+ diag::availability_opaque_types_only_version_newer,
2017
+ prettyPlatformString (targetPlatform (Context.LangOpts )),
2018
+ RequiredRange.getLowerEndpoint ());
2019
+
2022
2020
fixAvailability (ReferenceRange, ReferenceDC, RequiredRange, Context);
2023
2021
}
2024
2022
@@ -2028,20 +2026,12 @@ static void diagnosePotentialConcurrencyUnavailability(
2028
2026
ASTContext &Context = ReferenceDC->getASTContext ();
2029
2027
2030
2028
auto RequiredRange = Reason.getRequiredOSVersionRange ();
2031
- {
2032
- auto Err =
2033
- Context.Diags .diagnose (
2034
- ReferenceRange.Start ,
2035
- diag::availability_concurrency_only_version_newer,
2036
- prettyPlatformString (targetPlatform (Context.LangOpts )),
2037
- Reason.getRequiredOSVersionRange ().getLowerEndpoint ());
2038
-
2039
- // Direct a fixit to the error if an existing guard is nearly-correct
2040
- if (fixAvailabilityByNarrowingNearbyVersionCheck (ReferenceRange,
2041
- ReferenceDC,
2042
- RequiredRange, Context, Err))
2043
- return ;
2044
- }
2029
+
2030
+ Context.Diags .diagnose (ReferenceRange.Start ,
2031
+ diag::availability_concurrency_only_version_newer,
2032
+ prettyPlatformString (targetPlatform (Context.LangOpts )),
2033
+ RequiredRange.getLowerEndpoint ());
2034
+
2045
2035
fixAvailability (ReferenceRange, ReferenceDC, RequiredRange, Context);
2046
2036
}
2047
2037
@@ -2097,21 +2087,15 @@ bool TypeChecker::diagnosePotentialUnavailability(
2097
2087
bool WarnBeforeDeploymentTarget = false ) {
2098
2088
ASTContext &Context = ReferenceDC->getASTContext ();
2099
2089
2100
- auto RequiredRange = Reason.getRequiredOSVersionRange ();
2101
2090
bool IsError;
2102
- {
2103
- auto Diag = Context.Diags .diagnose (
2104
- ReferenceRange.Start ,
2105
- getPotentialUnavailabilityDiagnostic (
2106
- D, ReferenceDC, Reason, WarnBeforeDeploymentTarget, IsError));
2107
-
2108
- // Direct a fixit to the error if an existing guard is nearly-correct
2109
- if (fixAvailabilityByNarrowingNearbyVersionCheck (
2110
- ReferenceRange, ReferenceDC, RequiredRange, Context, Diag))
2111
- return IsError;
2112
- }
2091
+ Context.Diags .diagnose (
2092
+ ReferenceRange.Start ,
2093
+ getPotentialUnavailabilityDiagnostic (
2094
+ D, ReferenceDC, Reason, WarnBeforeDeploymentTarget, IsError));
2113
2095
2096
+ auto RequiredRange = Reason.getRequiredOSVersionRange ();
2114
2097
fixAvailability (ReferenceRange, ReferenceDC, RequiredRange, Context);
2098
+
2115
2099
return IsError;
2116
2100
}
2117
2101
@@ -2126,25 +2110,15 @@ void TypeChecker::diagnosePotentialAccessorUnavailability(
2126
2110
const AbstractStorageDecl *ASD = Accessor->getStorage ();
2127
2111
DeclName Name = ASD->getName ();
2128
2112
2113
+ auto RequiredRange = Reason.getRequiredOSVersionRange ();
2129
2114
auto &diag = ForInout ? diag::availability_inout_accessor_only_version_newer
2130
2115
: diag::availability_accessor_only_version_newer;
2131
2116
2132
- auto RequiredRange = Reason.getRequiredOSVersionRange ();
2133
- {
2134
- auto Err =
2135
- Context.Diags .diagnose (
2136
- ReferenceRange.Start , diag,
2137
- static_cast <unsigned >(Accessor->getAccessorKind ()), Name,
2138
- prettyPlatformString (targetPlatform (Context.LangOpts )),
2139
- Reason.getRequiredOSVersionRange ().getLowerEndpoint ());
2140
-
2141
-
2142
- // Direct a fixit to the error if an existing guard is nearly-correct
2143
- if (fixAvailabilityByNarrowingNearbyVersionCheck (ReferenceRange,
2144
- ReferenceDC,
2145
- RequiredRange, Context, Err))
2146
- return ;
2147
- }
2117
+ Context.Diags .diagnose (ReferenceRange.Start , diag,
2118
+ static_cast <unsigned >(Accessor->getAccessorKind ()),
2119
+ Name,
2120
+ prettyPlatformString (targetPlatform (Context.LangOpts )),
2121
+ RequiredRange.getLowerEndpoint ());
2148
2122
2149
2123
fixAvailability (ReferenceRange, ReferenceDC, RequiredRange, Context);
2150
2124
}
@@ -2172,33 +2146,29 @@ void TypeChecker::diagnosePotentialUnavailability(
2172
2146
const RootProtocolConformance *rootConf,
2173
2147
const ExtensionDecl *ext,
2174
2148
SourceLoc loc,
2175
- const DeclContext *dc ,
2176
- const UnavailabilityReason &reason ) {
2177
- ASTContext &ctx = dc ->getASTContext ();
2149
+ const DeclContext *ReferenceDC ,
2150
+ const UnavailabilityReason &Reason ) {
2151
+ ASTContext &Context = ReferenceDC ->getASTContext ();
2178
2152
2179
- auto requiredRange = reason .getRequiredOSVersionRange ();
2153
+ auto RequiredRange = Reason .getRequiredOSVersionRange ();
2180
2154
{
2181
2155
auto type = rootConf->getType ();
2182
2156
auto proto = rootConf->getProtocol ()->getDeclaredInterfaceType ();
2183
2157
2184
- auto diagID = (ctx.LangOpts .EnableConformanceAvailabilityErrors
2185
- ? diag::conformance_availability_only_version_newer
2186
- : diag::conformance_availability_only_version_newer_warn);
2187
- auto behavior = behaviorLimitForExplicitUnavailability (rootConf, dc);
2188
- auto err =
2189
- ctx.Diags .diagnose (
2190
- loc, diagID,
2191
- type, proto, prettyPlatformString (targetPlatform (ctx.LangOpts )),
2192
- reason.getRequiredOSVersionRange ().getLowerEndpoint ());
2158
+ const auto &diag =
2159
+ (Context.LangOpts .EnableConformanceAvailabilityErrors
2160
+ ? diag::conformance_availability_only_version_newer
2161
+ : diag::conformance_availability_only_version_newer_warn);
2162
+ auto behavior =
2163
+ behaviorLimitForExplicitUnavailability (rootConf, ReferenceDC);
2164
+ auto err = Context.Diags .diagnose (
2165
+ loc, diag, type, proto,
2166
+ prettyPlatformString (targetPlatform (Context.LangOpts )),
2167
+ RequiredRange.getLowerEndpoint ());
2193
2168
err.limitBehavior (behavior);
2194
-
2195
- // Direct a fixit to the error if an existing guard is nearly-correct
2196
- if (fixAvailabilityByNarrowingNearbyVersionCheck (loc, dc,
2197
- requiredRange, ctx, err))
2198
- return ;
2199
2169
}
2200
2170
2201
- fixAvailability (loc, dc, requiredRange, ctx );
2171
+ fixAvailability (loc, ReferenceDC, RequiredRange, Context );
2202
2172
}
2203
2173
2204
2174
const AvailableAttr *TypeChecker::getDeprecated (const Decl *D) {
@@ -2993,20 +2963,16 @@ static bool diagnosePotentialParameterizedProtocolUnavailability(
2993
2963
const UnavailabilityReason &Reason) {
2994
2964
ASTContext &Context = ReferenceDC->getASTContext ();
2995
2965
2966
+ Context.Diags .diagnose (
2967
+ ReferenceRange.Start ,
2968
+ diag::availability_parameterized_protocol_only_version_newer,
2969
+ prettyPlatformString (targetPlatform (Context.LangOpts )),
2970
+ Reason.getRequiredOSVersionRange ().getLowerEndpoint ());
2971
+
2996
2972
auto RequiredRange = Reason.getRequiredOSVersionRange ();
2997
- {
2998
- auto Err = Context.Diags .diagnose (
2999
- ReferenceRange.Start ,
3000
- diag::availability_parameterized_protocol_only_version_newer,
3001
- prettyPlatformString (targetPlatform (Context.LangOpts )),
3002
- Reason.getRequiredOSVersionRange ().getLowerEndpoint ());
3003
2973
3004
- // Direct a fixit to the error if an existing guard is nearly-correct
3005
- if (fixAvailabilityByNarrowingNearbyVersionCheck (
3006
- ReferenceRange, ReferenceDC, RequiredRange, Context, Err))
3007
- return true ;
3008
- }
3009
2974
fixAvailability (ReferenceRange, ReferenceDC, RequiredRange, Context);
2975
+
3010
2976
return true ;
3011
2977
}
3012
2978
0 commit comments