@@ -4341,23 +4341,37 @@ static void addUnavailableAttrs(ExtensionDecl *ext, NominalTypeDecl *nominal) {
4341
4341
ASTContext &ctx = nominal->getASTContext ();
4342
4342
llvm::VersionTuple noVersion;
4343
4343
4344
- // Add platform-version-specific @available attributes.
4345
- for (auto available : nominal->getAttrs ().getAttributes <AvailableAttr>()) {
4346
- if (available->Platform == PlatformKind::none)
4347
- continue ;
4344
+ // Add platform-version-specific @available attributes. Search from nominal
4345
+ // type declaration through its enclosing declarations to find the first one
4346
+ // with platform-specific attributes.
4347
+ for (Decl *enclosing = nominal;
4348
+ enclosing;
4349
+ enclosing = enclosing->getDeclContext ()
4350
+ ? enclosing->getDeclContext ()->getAsDecl ()
4351
+ : nullptr ) {
4352
+ bool anyPlatformSpecificAttrs = false ;
4353
+ for (auto available: enclosing->getAttrs ().getAttributes <AvailableAttr>()) {
4354
+ if (available->Platform == PlatformKind::none)
4355
+ continue ;
4348
4356
4349
- auto attr = new (ctx) AvailableAttr (
4350
- SourceLoc (), SourceRange (),
4351
- available->Platform ,
4352
- available->Message ,
4353
- " " , nullptr ,
4354
- available->Introduced .getValueOr (noVersion), SourceRange (),
4355
- available->Deprecated .getValueOr (noVersion), SourceRange (),
4356
- available->Obsoleted .getValueOr (noVersion), SourceRange (),
4357
- PlatformAgnosticAvailabilityKind::Unavailable,
4358
- /* implicit=*/ true ,
4359
- available->IsSPI );
4360
- ext->getAttrs ().add (attr);
4357
+ auto attr = new (ctx) AvailableAttr (
4358
+ SourceLoc (), SourceRange (),
4359
+ available->Platform ,
4360
+ available->Message ,
4361
+ " " , nullptr ,
4362
+ available->Introduced .getValueOr (noVersion), SourceRange (),
4363
+ available->Deprecated .getValueOr (noVersion), SourceRange (),
4364
+ available->Obsoleted .getValueOr (noVersion), SourceRange (),
4365
+ PlatformAgnosticAvailabilityKind::Unavailable,
4366
+ /* implicit=*/ true ,
4367
+ available->IsSPI );
4368
+ ext->getAttrs ().add (attr);
4369
+ anyPlatformSpecificAttrs = true ;
4370
+ }
4371
+
4372
+ // If we found any platform-specific availability attributes, we're done.
4373
+ if (anyPlatformSpecificAttrs)
4374
+ break ;
4361
4375
}
4362
4376
4363
4377
// Add the blanket "unavailable".
0 commit comments