@@ -4290,23 +4290,37 @@ static void addUnavailableAttrs(ExtensionDecl *ext, NominalTypeDecl *nominal) {
4290
4290
ASTContext &ctx = nominal->getASTContext ();
4291
4291
llvm::VersionTuple noVersion;
4292
4292
4293
- // Add platform-version-specific @available attributes.
4294
- for (auto available : nominal->getAttrs ().getAttributes <AvailableAttr>()) {
4295
- if (available->Platform == PlatformKind::none)
4296
- continue ;
4293
+ // Add platform-version-specific @available attributes. Search from nominal
4294
+ // type declaration through its enclosing declarations to find the first one
4295
+ // with platform-specific attributes.
4296
+ for (Decl *enclosing = nominal;
4297
+ enclosing;
4298
+ enclosing = enclosing->getDeclContext ()
4299
+ ? enclosing->getDeclContext ()->getAsDecl ()
4300
+ : nullptr ) {
4301
+ bool anyPlatformSpecificAttrs = false ;
4302
+ for (auto available: enclosing->getAttrs ().getAttributes <AvailableAttr>()) {
4303
+ if (available->Platform == PlatformKind::none)
4304
+ continue ;
4297
4305
4298
- auto attr = new (ctx) AvailableAttr (
4299
- SourceLoc (), SourceRange (),
4300
- available->Platform ,
4301
- available->Message ,
4302
- " " , nullptr ,
4303
- available->Introduced .getValueOr (noVersion), SourceRange (),
4304
- available->Deprecated .getValueOr (noVersion), SourceRange (),
4305
- available->Obsoleted .getValueOr (noVersion), SourceRange (),
4306
- PlatformAgnosticAvailabilityKind::Unavailable,
4307
- /* implicit=*/ true ,
4308
- available->IsSPI );
4309
- ext->getAttrs ().add (attr);
4306
+ auto attr = new (ctx) AvailableAttr (
4307
+ SourceLoc (), SourceRange (),
4308
+ available->Platform ,
4309
+ available->Message ,
4310
+ " " , nullptr ,
4311
+ available->Introduced .getValueOr (noVersion), SourceRange (),
4312
+ available->Deprecated .getValueOr (noVersion), SourceRange (),
4313
+ available->Obsoleted .getValueOr (noVersion), SourceRange (),
4314
+ PlatformAgnosticAvailabilityKind::Unavailable,
4315
+ /* implicit=*/ true ,
4316
+ available->IsSPI );
4317
+ ext->getAttrs ().add (attr);
4318
+ anyPlatformSpecificAttrs = true ;
4319
+ }
4320
+
4321
+ // If we found any platform-specific availability attributes, we're done.
4322
+ if (anyPlatformSpecificAttrs)
4323
+ break ;
4310
4324
}
4311
4325
4312
4326
// Add the blanket "unavailable".
0 commit comments