Skip to content

Commit 1732a4d

Browse files
authored
Merge pull request swiftlang#80331 from hborla/isolated-sendable-local-function
[Concurrency] Infer `@Sendable` for global actor isolated function references.
2 parents a810c72 + 0983bb5 commit 1732a4d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/Sema/TypeOfReference.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,18 @@ FunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
817817
return openType(type, replacements, locator);
818818
});
819819

820-
if (Context.LangOpts.hasFeature(Feature::InferSendableFromCaptures)) {
820+
// Infer @Sendable for global actor isolated function types under the
821+
// upcoming feature flag.
822+
if (Context.LangOpts.hasFeature(Feature::GlobalActorIsolatedTypesUsability)
823+
&& !adjustedTy->getExtInfo().isSendable()) {
824+
if (adjustedTy->getExtInfo().getIsolation().isGlobalActor()) {
825+
adjustedTy =
826+
adjustedTy->withExtInfo(adjustedTy->getExtInfo().withSendable());
827+
}
828+
}
829+
830+
if (Context.LangOpts.hasFeature(Feature::InferSendableFromCaptures) &&
831+
!adjustedTy->getExtInfo().isSendable()) {
821832
DeclContext *DC = nullptr;
822833
if (auto *FD = dyn_cast<AbstractFunctionDecl>(decl)) {
823834
DC = FD->getDeclContext();

test/Concurrency/global_actor_sendable_fn_type_inference.swift

+5
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ func allowNonSendableCaptures() {
2020
let _ = nonSendable // okay
2121
}
2222
}
23+
24+
func testLocalFunctionReference() {
25+
@MainActor func f() {}
26+
_ = f as any Sendable
27+
}

0 commit comments

Comments
 (0)