diff --git a/lib/Sema/TypeCheckConcurrency.cpp b/lib/Sema/TypeCheckConcurrency.cpp index c5faef3311309..9d2713b851f7e 100644 --- a/lib/Sema/TypeCheckConcurrency.cpp +++ b/lib/Sema/TypeCheckConcurrency.cpp @@ -2982,6 +2982,12 @@ namespace { ->mapTypeIntoContext(decl->getInterfaceType()) ->getReferenceStorageReferent(); + // Pack expansions are okay to capture as long as the pattern + // type is Sendable. + if (auto *expansion = type->getAs()) { + type = expansion->getPatternType(); + } + if (type->hasError()) continue; diff --git a/test/Concurrency/sendable_checking.swift b/test/Concurrency/sendable_checking.swift index 3e7a6d1df2301..a8d4837c2d2e5 100644 --- a/test/Concurrency/sendable_checking.swift +++ b/test/Concurrency/sendable_checking.swift @@ -507,3 +507,23 @@ func checkOpaqueType() -> some Sendable { class MainActorSub: MainActorSuper { struct Nested {} // no cycle } + +@available(SwiftStdlib 5.9, *) +struct SendablePack: Sendable { + let elements: (repeat each Element) +} + +@available(SwiftStdlib 5.1, *) +@MainActor +func sendablePacks( + _ element: repeat each Element +) async { + { @Sendable in + repeat _ = each element + }() + + await sendPack(repeat each element) +} + +@available(SwiftStdlib 5.1, *) +func sendPack(_: repeat each Element) async {}