Skip to content

Commit cc17c04

Browse files
authored
Merge pull request #82692 from slavapestov/fix-issue-82614
Concurrency: Move PackExpansionType check to swift::diagnoseNonSendableTypes()
2 parents c677554 + 66cda77 commit cc17c04

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
@@ -1052,11 +1052,17 @@ bool swift::diagnoseNonSendableTypes(
10521052
Type type, SendableCheckContext fromContext,
10531053
Type inDerivedConformance, SourceLoc loc,
10541054
llvm::function_ref<bool(Type, DiagnosticBehavior)> diagnose) {
1055+
auto &ctx = type->getASTContext();
1056+
10551057
// If the Sendable protocol is missing, do nothing.
1056-
auto proto = type->getASTContext().getProtocol(KnownProtocolKind::Sendable);
1058+
auto proto = ctx.getProtocol(KnownProtocolKind::Sendable);
10571059
if (!proto)
10581060
return false;
10591061

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

3058-
// Pack expansions are okay to capture as long as the pattern
3059-
// type is Sendable.
3060-
if (auto *expansion = type->getAs<PackExpansionType>()) {
3061-
type = expansion->getPatternType();
3062-
}
3063-
30643064
if (type->hasError())
30653065
continue;
30663066

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)