Skip to content

Commit be360b2

Browse files
committed
Perform generic substitutions for Sendable checking in protocol conformances
1 parent adf712e commit be360b2

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

lib/Sema/TypeCheckProtocol.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -2864,6 +2864,17 @@ static void emitDeclaredHereIfNeeded(DiagnosticEngine &diags,
28642864

28652865
bool ConformanceChecker::checkActorIsolation(
28662866
ValueDecl *requirement, ValueDecl *witness) {
2867+
/// Retrieve a concrete witness for Sendable checking.
2868+
auto getConcreteWitness = [&] {
2869+
if (auto genericEnv = witness->getInnermostDeclContext()
2870+
->getGenericEnvironmentOfContext()) {
2871+
return ConcreteDeclRef(
2872+
witness, genericEnv->getForwardingSubstitutionMap());
2873+
}
2874+
2875+
return ConcreteDeclRef(witness);
2876+
};
2877+
28672878
// Ensure that the witness is not actor-isolated in a manner that makes it
28682879
// unsuitable as a witness.
28692880
bool isCrossActor = false;
@@ -3014,8 +3025,8 @@ bool ConformanceChecker::checkActorIsolation(
30143025

30153026
case ActorIsolationRestriction::CrossActorSelf: {
30163027
if (diagnoseNonSendableTypesInReference(
3017-
witness, DC, witness->getLoc(),
3018-
ConcurrentReferenceKind::CrossActor)) {
3028+
getConcreteWitness(), DC, witness->getLoc(),
3029+
ConcurrentReferenceKind::CrossActor)) {
30193030
return true;
30203031
}
30213032

@@ -3145,8 +3156,8 @@ bool ConformanceChecker::checkActorIsolation(
31453156
return false;
31463157

31473158
return diagnoseNonSendableTypesInReference(
3148-
witness, DC, witness->getLoc(),
3149-
ConcurrentReferenceKind::CrossActor);
3159+
getConcreteWitness(), DC, witness->getLoc(),
3160+
ConcurrentReferenceKind::CrossActor);
31503161
}
31513162

31523163
// If the witness has a global actor but the requirement does not, we have

test/Concurrency/sendable_checking.swift

+12
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,15 @@ func testCV(
5353
// expected-note@-1{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
5454
acceptSendableFn(fn) // expected-error{{passing non-sendable parameter 'fn' to function expecting a @Sendable closure}}
5555
}
56+
57+
// rdar://83942484 - spurious Sendable diagnostics
58+
@available(SwiftStdlib 5.1, *)
59+
public protocol MyProto {
60+
func foo<F>(aFoo: F) async where F: Sendable
61+
}
62+
63+
@available(SwiftStdlib 5.1, *)
64+
public actor MyActor: MyProto {
65+
public func foo<F>(aFoo: F) async where F: Sendable { }
66+
public func bar<B>(aBar: B) async where B: Sendable { }
67+
}

0 commit comments

Comments
 (0)