Skip to content

Commit 0983bb5

Browse files
committed
[Concurrency] Infer @Sendable for global actor isolated function references.
1 parent a7b8cb7 commit 0983bb5

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
@@ -793,7 +793,18 @@ FunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
793793
return openType(type, replacements, locator);
794794
});
795795

796-
if (Context.LangOpts.hasFeature(Feature::InferSendableFromCaptures)) {
796+
// Infer @Sendable for global actor isolated function types under the
797+
// upcoming feature flag.
798+
if (Context.LangOpts.hasFeature(Feature::GlobalActorIsolatedTypesUsability)
799+
&& !adjustedTy->getExtInfo().isSendable()) {
800+
if (adjustedTy->getExtInfo().getIsolation().isGlobalActor()) {
801+
adjustedTy =
802+
adjustedTy->withExtInfo(adjustedTy->getExtInfo().withSendable());
803+
}
804+
}
805+
806+
if (Context.LangOpts.hasFeature(Feature::InferSendableFromCaptures) &&
807+
!adjustedTy->getExtInfo().isSendable()) {
797808
DeclContext *DC = nullptr;
798809
if (auto *FD = dyn_cast<AbstractFunctionDecl>(decl)) {
799810
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)