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