Skip to content

Commit 0696ec6

Browse files
committed
Sema: Ban implied 'Sendable' conformance when strict concurrency enabled
You can't do this anymore: struct G<T> {} protocol P: Sendable {} extension G: P where T: P {} Fixes rdar://95695543.
1 parent bb48d32 commit 0696ec6

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/Sema/TypeCheckProtocol.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -2415,8 +2415,16 @@ checkIndividualConformance(NormalProtocolConformance *conformance) {
24152415
ComplainLoc, diag::unchecked_conformance_not_special, ProtoType);
24162416
}
24172417

2418+
bool allowImpliedConditionalConformance = false;
2419+
if (Proto->isSpecificProtocol(KnownProtocolKind::Sendable)) {
2420+
if (Context.LangOpts.StrictConcurrencyLevel != StrictConcurrency::Complete)
2421+
allowImpliedConditionalConformance = true;
2422+
} else if (Proto->isMarkerProtocol()) {
2423+
allowImpliedConditionalConformance = true;
2424+
}
2425+
24182426
if (conformance->getSourceKind() == ConformanceEntryKind::Implied &&
2419-
!Proto->isMarkerProtocol()) {
2427+
!allowImpliedConditionalConformance) {
24202428
// We've got something like:
24212429
//
24222430
// protocol Foo : Proto {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 6
2+
3+
protocol P: Sendable {}
4+
protocol Q: Sendable {}
5+
6+
struct One<T> { // expected-note {{consider making generic parameter 'T' conform to the 'Sendable' protocol}}
7+
var t: T // expected-error {{stored property 't' of 'Sendable'-conforming generic struct 'One' has non-sendable type 'T'}}
8+
}
9+
10+
extension One: P where T: P {}
11+
// expected-error@-1 {{conditional conformance of type 'One<T>' to protocol 'P' does not imply conformance to inherited protocol 'Sendable'}}
12+
// expected-note@-2 {{did you mean to explicitly state the conformance like 'extension One: Sendable where ...'}}
13+
14+
struct Both<T> { // expected-note {{consider making generic parameter 'T' conform to the 'Sendable' protocol}}
15+
var t: T // expected-error {{stored property 't' of 'Sendable'-conforming generic struct 'Both' has non-sendable type 'T'}}
16+
}
17+
18+
extension Both: P where T: P {}
19+
// expected-error@-1 {{conditional conformance of type 'Both<T>' to protocol 'P' does not imply conformance to inherited protocol 'Sendable'}}
20+
// expected-note@-2 {{did you mean to explicitly state the conformance like 'extension Both: Sendable where ...'}}
21+
22+
extension Both: Q where T: Q {}
23+
24+
func takesSendable<T: Sendable>(_: T) {}
25+
26+
takesSendable(One<Int>(t: 3))
27+
takesSendable(Both<Int>(t: 3))

0 commit comments

Comments
 (0)