@@ -1877,56 +1877,54 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
1877
1877
1878
1878
SourceLoc attrLoc = attr->getLocation ();
1879
1879
1880
+ AvailabilityContext AttrRange{
1881
+ VersionRange::allGTE (attr->Introduced .value ())};
1882
+
1880
1883
// Find the innermost enclosing declaration with an availability
1881
1884
// range annotation and ensure that this attribute's available version range
1882
1885
// is fully contained within that declaration's range. If there is no such
1883
1886
// enclosing declaration, then there is nothing to check.
1884
1887
Optional<AvailabilityContext> EnclosingAnnotatedRange;
1885
- bool EnclosingDeclIsUnavailable = false ;
1886
- Decl *EnclosingDecl = getEnclosingDeclForDecl (D);
1887
-
1888
- while (EnclosingDecl) {
1889
- if (EnclosingDecl->getAttrs ().getUnavailable (Ctx)) {
1890
- EnclosingDeclIsUnavailable = true ;
1891
- break ;
1892
- }
1893
-
1894
- EnclosingAnnotatedRange =
1895
- AvailabilityInference::annotatedAvailableRange (EnclosingDecl, Ctx);
1896
-
1897
- if (EnclosingAnnotatedRange.has_value ())
1898
- break ;
1899
1888
1900
- EnclosingDecl = getEnclosingDeclForDecl (EnclosingDecl);
1901
- }
1902
-
1903
- AvailabilityContext AttrRange{
1904
- VersionRange::allGTE (attr->Introduced .value ())};
1905
-
1906
- if (EnclosingDecl) {
1907
- if (EnclosingDeclIsUnavailable) {
1889
+ if (auto *parent = getEnclosingDeclForDecl (D)) {
1890
+ if (auto enclosingUnavailable = parent->getSemanticUnavailableAttr ()) {
1908
1891
if (!AttrRange.isKnownUnreachable ()) {
1909
- diagnose (D->isImplicit () ? EnclosingDecl->getLoc ()
1892
+ const Decl *enclosingDecl = enclosingUnavailable.value ().second ;
1893
+ diagnose (D->isImplicit () ? enclosingDecl->getLoc ()
1910
1894
: attr->getLocation (),
1911
1895
diag::availability_decl_more_than_unavailable_enclosing,
1912
1896
D->getDescriptiveKind ());
1913
- diagnose (EnclosingDecl ->getLoc (),
1897
+ diagnose (parent ->getLoc (),
1914
1898
diag::availability_decl_more_than_unavailable_enclosing_here);
1915
1899
}
1916
- } else if (!AttrRange.isContainedIn (EnclosingAnnotatedRange.value ())) {
1917
- diagnose (D->isImplicit () ? EnclosingDecl->getLoc () : attr->getLocation (),
1918
- diag::availability_decl_more_than_enclosing,
1919
- D->getDescriptiveKind ());
1920
- if (D->isImplicit ())
1921
- diagnose (EnclosingDecl->getLoc (),
1922
- diag::availability_implicit_decl_here,
1923
- D->getDescriptiveKind (),
1900
+ } else if (auto enclosingAvailable =
1901
+ parent->getSemanticAvailableRangeAttr ()) {
1902
+ const AvailableAttr *enclosingAttr = enclosingAvailable.value ().first ;
1903
+ const Decl *enclosingDecl = enclosingAvailable.value ().second ;
1904
+ EnclosingAnnotatedRange.emplace (
1905
+ VersionRange::allGTE (enclosingAttr->Introduced .value ()));
1906
+ if (!AttrRange.isContainedIn (*EnclosingAnnotatedRange)) {
1907
+ // Members of extensions of nominal types with available ranges were
1908
+ // not diagnosed previously, so only emit a warning in that case.
1909
+ auto limit = (enclosingDecl != parent && isa<ExtensionDecl>(parent))
1910
+ ? DiagnosticBehavior::Warning
1911
+ : DiagnosticBehavior::Unspecified;
1912
+ diagnose (D->isImplicit () ? enclosingDecl->getLoc ()
1913
+ : attr->getLocation (),
1914
+ diag::availability_decl_more_than_enclosing,
1915
+ D->getDescriptiveKind ())
1916
+ .limitBehavior (limit);
1917
+ if (D->isImplicit ())
1918
+ diagnose (enclosingDecl->getLoc (),
1919
+ diag::availability_implicit_decl_here,
1920
+ D->getDescriptiveKind (),
1921
+ prettyPlatformString (targetPlatform (Ctx.LangOpts )),
1922
+ AttrRange.getOSVersion ().getLowerEndpoint ());
1923
+ diagnose (enclosingDecl->getLoc (),
1924
+ diag::availability_decl_more_than_enclosing_here,
1924
1925
prettyPlatformString (targetPlatform (Ctx.LangOpts )),
1925
- AttrRange.getOSVersion ().getLowerEndpoint ());
1926
- diagnose (EnclosingDecl->getLoc (),
1927
- diag::availability_decl_more_than_enclosing_here,
1928
- prettyPlatformString (targetPlatform (Ctx.LangOpts )),
1929
- EnclosingAnnotatedRange->getOSVersion ().getLowerEndpoint ());
1926
+ EnclosingAnnotatedRange->getOSVersion ().getLowerEndpoint ());
1927
+ }
1930
1928
}
1931
1929
}
1932
1930
0 commit comments