Skip to content

Commit 16676fd

Browse files
committed
Fix availability inference for unownedExecutor.
Rather that copying availability directly from `UnownedExecutorRef`, we need to properly infer availability from both it and the enclosing context. Otherwise, the synthesized `unownedExecutor` will have an availability that could conflict with our enclosing declaration. Fixes rdar://83246377.
1 parent b03cde6 commit 16676fd

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/Sema/DerivedConformanceActor.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,14 @@ static ValueDecl *deriveActor_unownedExecutor(DerivedConformance &derived) {
153153
if (property->getFormalAccess() == AccessLevel::Open)
154154
property->overwriteAccess(AccessLevel::Public);
155155

156-
// Clone any @available attributes from UnownedSerialExecutor.
157-
// Really, though, the whole actor probably needs to be marked as
158-
// unavailable.
159-
for (auto attr: executorDecl->getAttrs().getAttributes<AvailableAttr>())
160-
property->getAttrs().add(attr->clone(ctx, /*implicit*/true));
156+
// Infer availability.
157+
SmallVector<const Decl *, 2> asAvailableAs;
158+
asAvailableAs.push_back(executorDecl);
159+
if (auto enclosingDecl = property->getInnermostDeclWithAvailability())
160+
asAvailableAs.push_back(enclosingDecl);
161+
162+
AvailabilityInference::applyInferredAvailableAttrs(
163+
property, asAvailableAs, ctx);
161164

162165
auto getter =
163166
derived.addGetterToReadOnlyDerivedProperty(property, executorType);

test/Concurrency/concurrency_availability.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ actor A { } // expected-error{{concurrency is only available in}}
1111
// Allow this without any availability for Historical Reasons.
1212
public func swift_deletedAsyncMethodError() async {
1313
}
14+
15+
// Ensure that our synthesis of the actor's unownedExecutor does not cause
16+
// availability errors.
17+
@available(macOS 12.0, *)
18+
struct S {
19+
actor A {
20+
}
21+
}

0 commit comments

Comments
 (0)