Skip to content

Commit d164a7c

Browse files
committed
[Concurrency] Allow capturing pack expansions in @Sendable closures
if the pattern type conforms to `Sendable`.
1 parent c433242 commit d164a7c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Diff for: lib/Sema/TypeCheckConcurrency.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -2982,6 +2982,12 @@ namespace {
29822982
->mapTypeIntoContext(decl->getInterfaceType())
29832983
->getReferenceStorageReferent();
29842984

2985+
// Pack expansions are okay to capture as long as the pattern
2986+
// type is Sendable.
2987+
if (auto *expansion = type->getAs<PackExpansionType>()) {
2988+
type = expansion->getPatternType();
2989+
}
2990+
29852991
if (type->hasError())
29862992
continue;
29872993

Diff for: test/Concurrency/sendable_checking.swift

+19
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,22 @@ func checkOpaqueType() -> some Sendable {
507507
class MainActorSub: MainActorSuper<MainActorSub.Nested> {
508508
struct Nested {} // no cycle
509509
}
510+
511+
@available(SwiftStdlib 5.1, *)
512+
struct SendablePack<each Element: Sendable>: Sendable {
513+
let elements: (repeat each Elements)
514+
}
515+
516+
@available(SwiftStdlib 5.1, *)
517+
@MainActor
518+
func sendablePacks<each Element: Sendable>(
519+
_ element: repeat each Element
520+
) async {
521+
{ @Sendable in
522+
repeat _ = each parameters
523+
}()
524+
525+
await sendPack(repeat each element)
526+
}
527+
528+
func sendPack<each Element>(_: repeat each Element) async {}

0 commit comments

Comments
 (0)