Skip to content

Commit b0b5f0c

Browse files
authored
Merge pull request #59942 from DougGregor/nonsendable-available-nested-5.7
2 parents a14f05e + 2639d19 commit b0b5f0c

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4290,23 +4290,37 @@ static void addUnavailableAttrs(ExtensionDecl *ext, NominalTypeDecl *nominal) {
42904290
ASTContext &ctx = nominal->getASTContext();
42914291
llvm::VersionTuple noVersion;
42924292

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;
42974305

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;
43104324
}
43114325

43124326
// Add the blanket "unavailable".

test/ModuleInterface/sendable_availability.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ public struct X { }
1111
@_nonSendable
1212
public struct Y { }
1313

14+
@available(macOS 11.0, *)
15+
extension X {
16+
@available(macOS 12.0, *)
17+
@_nonSendable
18+
public struct A { }
19+
20+
@_nonSendable
21+
public struct B { }
22+
}
23+
1424
// RUN: %FileCheck %s <%t/Library.swiftinterface
1525
// CHECK: @available(macOS 11.0, *)
1626
// CHECK-NEXT: public struct X
@@ -22,5 +32,13 @@ public struct Y { }
2232
// CHECK: @available(*, unavailable)
2333
// CHECK-NEXT: extension Library.Y{{( )?}}: @unchecked Swift.Sendable {
2434

35+
// CHECK: @available(macOS, unavailable, introduced: 12.0)
36+
// CHECK-NEXT: @available(*, unavailable)
37+
// CHECK-NEXT: extension Library.X.A{{( )?}}: @unchecked Swift.Sendable {
38+
39+
// CHECK: @available(macOS, unavailable, introduced: 11.0)
40+
// CHECK-NEXT: @available(*, unavailable)
41+
// CHECK-NEXT: extension Library.X.B{{( )?}}: @unchecked Swift.Sendable {
42+
2543
// RUN: %target-swift-frontend -typecheck -enable-library-evolution -target %target-cpu-apple-macosx12.0 -emit-module-interface-path %t/Library.swiftinterface -DLIBRARY -module-name Library %s -module-interface-preserve-types-as-written
2644
// RUN: %FileCheck %s <%t/Library.swiftinterface

0 commit comments

Comments
 (0)