Skip to content

Commit dd1a85c

Browse files
committed
[Concurrency] Implicit global actor attributes imply Sendable.
Sendable derivation was only checking for explicit global actor attributes. It should also account for inferred global actor attributes, e.g. from protocol conformances. (cherry picked from commit e044e3d)
1 parent bd41510 commit dd1a85c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6055,7 +6055,7 @@ ProtocolConformance *swift::deriveImplicitSendableConformance(
60556055
}
60566056

60576057
// A non-protocol type with a global actor is implicitly Sendable.
6058-
if (nominal->getGlobalActorAttr()) {
6058+
if (getActorIsolation(nominal).isGlobalActor()) {
60596059
// Form the implicit conformance to Sendable.
60606060
return formConformance(nullptr);
60616061
}

test/Concurrency/sendable_checking.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,23 @@ struct DowngradeForPreconcurrency {
407407
}
408408
}
409409
}
410+
411+
@available(SwiftStdlib 5.1, *)
412+
@MainActor protocol InferMainActor {}
413+
414+
@available(SwiftStdlib 5.1, *)
415+
struct ImplicitSendableViaMain: InferMainActor {}
416+
417+
@available(SwiftStdlib 5.1, *)
418+
extension ImplicitSendableViaMain {
419+
nonisolated func capture() {
420+
Task { @MainActor in
421+
_ = self
422+
}
423+
}
424+
}
425+
426+
@available(SwiftStdlib 5.1, *)
427+
struct TestImplicitSendable: Sendable {
428+
var x: ImplicitSendableViaMain
429+
}

0 commit comments

Comments
 (0)