@@ -2109,6 +2109,18 @@ static Decl *getEnclosingDeclForDecl(Decl *D) {
21092109 return D->getDeclContext ()->getInnermostDeclarationDeclContext ();
21102110}
21112111
2112+ static std::optional<std::pair<const AvailableAttr *, const Decl *>>
2113+ getSemanticAvailableRangeDeclAndAttr (const Decl *decl) {
2114+ if (auto attr = AvailabilityInference::attrForAnnotatedAvailableRange (decl))
2115+ return std::make_pair (attr, decl);
2116+
2117+ if (auto *parent =
2118+ AvailabilityInference::parentDeclForInferredAvailability (decl))
2119+ return getSemanticAvailableRangeDeclAndAttr (parent);
2120+
2121+ return std::nullopt ;
2122+ }
2123+
21122124void AttributeChecker::visitAvailableAttr (AvailableAttr *attr) {
21132125 if (Ctx.LangOpts .DisableAvailabilityChecking )
21142126 return ;
@@ -2214,7 +2226,7 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
22142226
22152227 if (auto *parent = getEnclosingDeclForDecl (D)) {
22162228 if (auto enclosingAvailable =
2217- parent-> getSemanticAvailableRangeAttr ( )) {
2229+ getSemanticAvailableRangeDeclAndAttr (parent )) {
22182230 const AvailableAttr *enclosingAttr = enclosingAvailable.value ().first ;
22192231 const Decl *enclosingDecl = enclosingAvailable.value ().second ;
22202232 EnclosingAnnotatedRange.emplace (
@@ -4833,7 +4845,8 @@ void AttributeChecker::checkBackDeployedAttrs(
48334845 // Verify that the decl is available before the back deployment boundary.
48344846 // If it's not, the attribute doesn't make sense since the back deployment
48354847 // fallback could never be executed at runtime.
4836- if (auto availableRangeAttrPair = VD->getSemanticAvailableRangeAttr ()) {
4848+ if (auto availableRangeAttrPair =
4849+ getSemanticAvailableRangeDeclAndAttr (VD)) {
48374850 auto beforePlatformString = prettyPlatformString (Attr->Platform );
48384851 auto beforeVersion = Attr->Version ;
48394852 auto availableAttr = availableRangeAttrPair.value ().first ;
0 commit comments