@@ -1534,6 +1534,9 @@ static void fixItAvailableAttrRename(TypeChecker &TC,
1534
1534
const ValueDecl *renamedDecl,
1535
1535
const AvailableAttr *attr,
1536
1536
const ApplyExpr *call) {
1537
+ if (isa<AccessorDecl>(renamedDecl))
1538
+ return ;
1539
+
1537
1540
ParsedDeclName parsed = swift::parseDeclName (attr->Rename );
1538
1541
if (!parsed)
1539
1542
return ;
@@ -1906,6 +1909,26 @@ describeRename(ASTContext &ctx, const AvailableAttr *attr, const ValueDecl *D,
1906
1909
return ReplacementDeclKind::None;
1907
1910
}
1908
1911
1912
+ // / Returns a value that can be used to select between accessor kinds in
1913
+ // / diagnostics.
1914
+ // /
1915
+ // / This is correlated with diag::availability_deprecated and others.
1916
+ static std::pair<unsigned , DeclName>
1917
+ getAccessorKindAndNameForDiagnostics (const ValueDecl *D) {
1918
+ // This should always be one more than the last AccessorKind supported in
1919
+ // the diagnostics. If you need to change it, change the assertion below as
1920
+ // well.
1921
+ static const unsigned NOT_ACCESSOR_INDEX = 2 ;
1922
+
1923
+ if (auto *accessor = dyn_cast<AccessorDecl>(D)) {
1924
+ DeclName Name = accessor->getStorage ()->getFullName ();
1925
+ assert (accessor->isGetterOrSetter ());
1926
+ return {static_cast <unsigned >(accessor->getAccessorKind ()), Name};
1927
+ }
1928
+
1929
+ return {NOT_ACCESSOR_INDEX, D->getFullName ()};
1930
+ }
1931
+
1909
1932
void TypeChecker::diagnoseIfDeprecated (SourceRange ReferenceRange,
1910
1933
const DeclContext *ReferenceDC,
1911
1934
const ValueDecl *DeprecatedDecl,
@@ -1933,26 +1956,19 @@ void TypeChecker::diagnoseIfDeprecated(SourceRange ReferenceRange,
1933
1956
}
1934
1957
1935
1958
DeclName Name;
1936
- Optional<unsigned > rawAccessorKind;
1937
- if (auto *accessor = dyn_cast<AccessorDecl>(DeprecatedDecl)) {
1938
- Name = accessor->getStorage ()->getFullName ();
1939
- assert (accessor->isGetterOrSetter ());
1940
- rawAccessorKind = static_cast <unsigned >(accessor->getAccessorKind ());
1941
- } else {
1942
- Name = DeprecatedDecl->getFullName ();
1943
- }
1959
+ unsigned RawAccessorKind;
1960
+ std::tie (RawAccessorKind, Name) =
1961
+ getAccessorKindAndNameForDiagnostics (DeprecatedDecl);
1944
1962
1945
1963
StringRef Platform = Attr->prettyPlatformString ();
1946
1964
clang::VersionTuple DeprecatedVersion;
1947
1965
if (Attr->Deprecated )
1948
1966
DeprecatedVersion = Attr->Deprecated .getValue ();
1949
1967
1950
- static const unsigned NOT_ACCESSOR_INDEX = 2 ;
1951
1968
if (Attr->Message .empty () && Attr->Rename .empty ()) {
1952
1969
diagnose (ReferenceRange.Start , diag::availability_deprecated,
1953
- rawAccessorKind.getValueOr (NOT_ACCESSOR_INDEX), Name,
1954
- Attr->hasPlatform (), Platform, Attr->Deprecated .hasValue (),
1955
- DeprecatedVersion)
1970
+ RawAccessorKind, Name, Attr->hasPlatform (), Platform,
1971
+ Attr->Deprecated .hasValue (), DeprecatedVersion)
1956
1972
.highlight (Attr->getRange ());
1957
1973
return ;
1958
1974
}
@@ -1965,22 +1981,21 @@ void TypeChecker::diagnoseIfDeprecated(SourceRange ReferenceRange,
1965
1981
if (!Attr->Message .empty ()) {
1966
1982
EncodedDiagnosticMessage EncodedMessage (Attr->Message );
1967
1983
diagnose (ReferenceRange.Start , diag::availability_deprecated_msg,
1968
- rawAccessorKind. getValueOr (NOT_ACCESSOR_INDEX ), Name ,
1969
- Attr->hasPlatform (), Platform, Attr-> Deprecated .hasValue (),
1970
- DeprecatedVersion, EncodedMessage.Message )
1984
+ RawAccessorKind, Name, Attr-> hasPlatform ( ), Platform ,
1985
+ Attr->Deprecated .hasValue (), DeprecatedVersion ,
1986
+ EncodedMessage.Message )
1971
1987
.highlight (Attr->getRange ());
1972
1988
} else {
1973
1989
unsigned rawReplaceKind = static_cast <unsigned >(
1974
1990
replacementDeclKind.getValueOr (ReplacementDeclKind::None));
1975
1991
diagnose (ReferenceRange.Start , diag::availability_deprecated_rename,
1976
- rawAccessorKind.getValueOr (NOT_ACCESSOR_INDEX), Name,
1977
- Attr->hasPlatform (), Platform, Attr->Deprecated .hasValue (),
1978
- DeprecatedVersion, replacementDeclKind.hasValue (), rawReplaceKind,
1979
- newName)
1992
+ RawAccessorKind, Name, Attr->hasPlatform (), Platform,
1993
+ Attr->Deprecated .hasValue (), DeprecatedVersion,
1994
+ replacementDeclKind.hasValue (), rawReplaceKind, newName)
1980
1995
.highlight (Attr->getRange ());
1981
1996
}
1982
1997
1983
- if (!Attr->Rename .empty () && !rawAccessorKind. hasValue ( )) {
1998
+ if (!Attr->Rename .empty () && !isa<AccessorDecl>(DeprecatedDecl )) {
1984
1999
auto renameDiag = diagnose (ReferenceRange.Start ,
1985
2000
diag::note_deprecated_rename,
1986
2001
newName);
@@ -1999,8 +2014,13 @@ void TypeChecker::diagnoseUnavailableOverride(ValueDecl *override,
1999
2014
else
2000
2015
diagnose (override , diag::override_unavailable_msg,
2001
2016
override ->getBaseName (), attr->Message );
2017
+
2018
+ DeclName name;
2019
+ unsigned rawAccessorKind;
2020
+ std::tie (rawAccessorKind, name) =
2021
+ getAccessorKindAndNameForDiagnostics (base);
2002
2022
diagnose (base, diag::availability_marked_unavailable,
2003
- base-> getFullName () );
2023
+ rawAccessorKind, name );
2004
2024
return ;
2005
2025
}
2006
2026
@@ -2127,7 +2147,9 @@ bool TypeChecker::diagnoseExplicitUnavailability(
2127
2147
}
2128
2148
2129
2149
SourceLoc Loc = R.Start ;
2130
- auto Name = D->getFullName ();
2150
+ DeclName Name;
2151
+ unsigned RawAccessorKind;
2152
+ std::tie (RawAccessorKind, Name) = getAccessorKindAndNameForDiagnostics (D);
2131
2153
2132
2154
switch (Attr->getPlatformAgnosticAvailability ()) {
2133
2155
case PlatformAgnosticAvailabilityKind::Deprecated:
@@ -2150,14 +2172,14 @@ bool TypeChecker::diagnoseExplicitUnavailability(
2150
2172
2151
2173
if (Attr->Message .empty ()) {
2152
2174
auto diag = diagnose (Loc, diag::availability_decl_unavailable_rename,
2153
- Name, replaceKind.hasValue (), rawReplaceKind ,
2154
- newName);
2175
+ RawAccessorKind, Name, replaceKind.hasValue (),
2176
+ rawReplaceKind, newName);
2155
2177
attachRenameFixIts (diag);
2156
2178
} else {
2157
2179
EncodedDiagnosticMessage EncodedMessage (Attr->Message );
2158
2180
auto diag = diagnose (Loc, diag::availability_decl_unavailable_rename_msg,
2159
- Name, replaceKind.hasValue (), rawReplaceKind ,
2160
- newName, EncodedMessage.Message );
2181
+ RawAccessorKind, Name, replaceKind.hasValue (),
2182
+ rawReplaceKind, newName, EncodedMessage.Message );
2161
2183
attachRenameFixIts (diag);
2162
2184
}
2163
2185
} else if (isSubscriptReturningString (D, Context)) {
@@ -2171,12 +2193,13 @@ bool TypeChecker::diagnoseExplicitUnavailability(
2171
2193
} else if (Attr->Message .empty ()) {
2172
2194
diagnose (Loc, inSwift ? diag::availability_decl_unavailable_in_swift
2173
2195
: diag::availability_decl_unavailable,
2174
- Name).highlight (R);
2196
+ RawAccessorKind, Name)
2197
+ .highlight (R);
2175
2198
} else {
2176
2199
EncodedDiagnosticMessage EncodedMessage (Attr->Message );
2177
2200
diagnose (Loc, inSwift ? diag::availability_decl_unavailable_in_swift_msg
2178
2201
: diag::availability_decl_unavailable_msg,
2179
- Name, EncodedMessage.Message )
2202
+ RawAccessorKind, Name, EncodedMessage.Message )
2180
2203
.highlight (R);
2181
2204
}
2182
2205
break ;
@@ -2191,20 +2214,23 @@ bool TypeChecker::diagnoseExplicitUnavailability(
2191
2214
case AvailableVersionComparison::Unavailable:
2192
2215
if (Attr->isLanguageVersionSpecific ()
2193
2216
&& Attr->Introduced .hasValue ())
2194
- diagnose (D, diag::availability_introduced_in_swift, Name,
2195
- *Attr->Introduced ).highlight (Attr->getRange ());
2217
+ diagnose (D, diag::availability_introduced_in_swift,
2218
+ RawAccessorKind, Name, *Attr->Introduced )
2219
+ .highlight (Attr->getRange ());
2196
2220
else
2197
- diagnose (D, diag::availability_marked_unavailable, Name)
2221
+ diagnose (D, diag::availability_marked_unavailable, RawAccessorKind, Name)
2198
2222
.highlight (Attr->getRange ());
2199
2223
break ;
2200
2224
2201
2225
case AvailableVersionComparison::Obsoleted:
2202
2226
// FIXME: Use of the platformString here is non-awesome for application
2203
2227
// extensions.
2204
- diagnose (D, diag::availability_obsoleted, Name,
2228
+ diagnose (D, diag::availability_obsoleted,
2229
+ RawAccessorKind, Name,
2205
2230
(Attr->isLanguageVersionSpecific () ?
2206
2231
" Swift" : Attr->prettyPlatformString ()),
2207
- *Attr->Obsoleted ).highlight (Attr->getRange ());
2232
+ *Attr->Obsoleted )
2233
+ .highlight (Attr->getRange ());
2208
2234
break ;
2209
2235
}
2210
2236
return true ;
@@ -2433,8 +2459,18 @@ class AvailabilityWalker : public ASTWalker {
2433
2459
return ;
2434
2460
}
2435
2461
2436
- // Make sure not to diagnose an accessor if we already complained about
2437
- // the property/subscript.
2462
+ // If the property/subscript is unconditionally unavailable, don't bother
2463
+ // with any of the rest of this.
2464
+ if (AvailableAttr::isUnavailable (D->getStorage ()))
2465
+ return ;
2466
+
2467
+ if (TC.diagnoseExplicitUnavailability (D, ReferenceRange, ReferenceDC,
2468
+ /* call*/ nullptr )) {
2469
+ return ;
2470
+ }
2471
+
2472
+ // Make sure not to diagnose an accessor's deprecation if we already
2473
+ // complained about the property/subscript.
2438
2474
if (!TypeChecker::getDeprecated (D->getStorage ()))
2439
2475
TC.diagnoseIfDeprecated (ReferenceRange, ReferenceDC, D, /* call*/ nullptr );
2440
2476
@@ -2549,9 +2585,14 @@ bool AvailabilityWalker::diagnoseIncDecRemoval(const ValueDecl *D,
2549
2585
}
2550
2586
2551
2587
if (!replacement.empty ()) {
2588
+ DeclName Name;
2589
+ unsigned RawAccessorKind;
2590
+ std::tie (RawAccessorKind, Name) = getAccessorKindAndNameForDiagnostics (D);
2591
+
2552
2592
// If we emit a deprecation diagnostic, produce a fixit hint as well.
2553
2593
auto diag = TC.diagnose (R.Start , diag::availability_decl_unavailable_msg,
2554
- D->getFullName (), " it has been removed in Swift 3" );
2594
+ RawAccessorKind, Name,
2595
+ " it has been removed in Swift 3" );
2555
2596
if (isa<PrefixUnaryExpr>(call)) {
2556
2597
// Prefix: remove the ++ or --.
2557
2598
diag.fixItRemove (call->getFn ()->getSourceRange ());
@@ -2594,9 +2635,13 @@ bool AvailabilityWalker::diagnoseMemoryLayoutMigration(const ValueDecl *D,
2594
2635
if (!args)
2595
2636
return false ;
2596
2637
2638
+ DeclName Name;
2639
+ unsigned RawAccessorKind;
2640
+ std::tie (RawAccessorKind, Name) = getAccessorKindAndNameForDiagnostics (D);
2641
+
2597
2642
EncodedDiagnosticMessage EncodedMessage (Attr->Message );
2598
2643
auto diag = TC.diagnose (R.Start , diag::availability_decl_unavailable_msg,
2599
- D-> getFullName () , EncodedMessage.Message );
2644
+ RawAccessorKind, Name , EncodedMessage.Message );
2600
2645
diag.highlight (R);
2601
2646
2602
2647
auto subject = args->getSubExpr ();
0 commit comments