Skip to content

Commit 374b71f

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 c446515 commit 374b71f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2414,8 +2414,16 @@ checkIndividualConformance(NormalProtocolConformance *conformance) {
24142414
ComplainLoc, diag::unchecked_conformance_not_special, ProtoType);
24152415
}
24162416

2417+
bool allowImpliedConditionalConformance = false;
2418+
if (Proto->isSpecificProtocol(KnownProtocolKind::Sendable)) {
2419+
if (Context.LangOpts.StrictConcurrencyLevel != StrictConcurrency::Complete)
2420+
allowImpliedConditionalConformance = true;
2421+
} else if (Proto->isMarkerProtocol()) {
2422+
allowImpliedConditionalConformance = true;
2423+
}
2424+
24172425
if (conformance->getSourceKind() == ConformanceEntryKind::Implied &&
2418-
!Proto->isMarkerProtocol()) {
2426+
!allowImpliedConditionalConformance) {
24192427
// We've got something like:
24202428
//
24212429
// protocol Foo : Proto {}
Lines changed: 27 additions & 0 deletions
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)