Skip to content

Commit 6fbf38f

Browse files
authored
Merge pull request #82693 from slavapestov/fix-issue-82614-6.2
[6.2] Concurrency: Move PackExpansionType check to swift::diagnoseNonSendableTypes()
2 parents e3f8048 + 14a2775 commit 6fbf38f

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,11 +1053,17 @@ bool swift::diagnoseNonSendableTypes(
10531053
Type type, SendableCheckContext fromContext,
10541054
Type inDerivedConformance, SourceLoc loc,
10551055
llvm::function_ref<bool(Type, DiagnosticBehavior)> diagnose) {
1056+
auto &ctx = type->getASTContext();
1057+
10561058
// If the Sendable protocol is missing, do nothing.
1057-
auto proto = type->getASTContext().getProtocol(KnownProtocolKind::Sendable);
1059+
auto proto = ctx.getProtocol(KnownProtocolKind::Sendable);
10581060
if (!proto)
10591061
return false;
10601062

1063+
// Unwrap pack expansions here to allow packs of Sendable type.
1064+
if (auto *expansion = type->getAs<PackExpansionType>())
1065+
type = PackType::get(ctx, {expansion});
1066+
10611067
// FIXME: More detail for unavailable conformances.
10621068
auto conformance = lookupConformance(type, proto, /*allowMissing=*/true);
10631069
if (conformance.isInvalid() || conformance.hasUnavailableConformance()) {
@@ -3071,12 +3077,6 @@ namespace {
30713077
->mapTypeIntoContext(decl->getInterfaceType())
30723078
->getReferenceStorageReferent();
30733079

3074-
// Pack expansions are okay to capture as long as the pattern
3075-
// type is Sendable.
3076-
if (auto *expansion = type->getAs<PackExpansionType>()) {
3077-
type = expansion->getPatternType();
3078-
}
3079-
30803080
if (type->hasError())
30813081
continue;
30823082

test/Concurrency/sendable_checking.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,27 @@ func test(value: (_: Int, _: () -> Void)) {
534534
takesSendable(value.1) // Ok
535535
// expected-warning@-1 {{converting non-Sendable function value to '@Sendable () -> Void' may introduce data races}}
536536
}
537+
538+
// Don't forget about parameter packs -- https://github.com/swiftlang/swift/issues/82614
539+
540+
@available(SwiftStdlib 5.1, *)
541+
protocol PackProto {
542+
func foo<each A: Sendable>(_ a: repeat each A) async
543+
func bar<each A>(_ a: repeat each A) async
544+
// expected-note@-1 {{consider making generic parameter 'each A' conform to the 'Sendable' protocol}}
545+
}
546+
547+
@available(SwiftStdlib 5.1, *)
548+
actor PackActor: PackProto {
549+
func foo<each A: Sendable>(_ a: repeat each A) async {
550+
for b in repeat (each a) {
551+
print(b)
552+
}
553+
}
554+
func bar<each A>(_ a: repeat each A) async {
555+
// expected-warning@-1 {{non-Sendable parameter type 'repeat each A' cannot be sent from caller of protocol requirement 'bar' into actor-isolated implementation; this is an error in the Swift 6 language mode}}
556+
for b in repeat (each a) {
557+
print(b)
558+
}
559+
}
560+
}

0 commit comments

Comments
 (0)