Skip to content

Commit 2e81274

Browse files
committed
Prior to Swift 6, diagnostic unavailable Sendable conformances via warnings.
1 parent 9db56da commit 2e81274

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,7 @@ bool swift::diagnoseExplicitUnavailability(SourceLoc loc,
24462446
auto proto = rootConf->getProtocol()->getDeclaredInterfaceType();
24472447

24482448
StringRef platform;
2449+
auto behavior = DiagnosticBehavior::Unspecified;
24492450
switch (attr->getPlatformAgnosticAvailability()) {
24502451
case PlatformAgnosticAvailabilityKind::Deprecated:
24512452
llvm_unreachable("shouldn't see deprecations in explicit unavailability");
@@ -2456,6 +2457,12 @@ bool swift::diagnoseExplicitUnavailability(SourceLoc loc,
24562457
// This was platform-specific; indicate the platform.
24572458
platform = attr->prettyPlatformString();
24582459
break;
2460+
} else if (rootConf->getProtocol()->isSpecificProtocol(
2461+
KnownProtocolKind::Sendable) &&
2462+
!ctx.LangOpts.isSwiftVersionAtLeast(6)) {
2463+
// Downgrade unavailable Sendable conformances to warnings prior to
2464+
// Swift 6.
2465+
behavior = DiagnosticBehavior::Warning;
24592466
}
24602467
LLVM_FALLTHROUGH;
24612468

@@ -2474,7 +2481,8 @@ bool swift::diagnoseExplicitUnavailability(SourceLoc loc,
24742481
EncodedDiagnosticMessage EncodedMessage(attr->Message);
24752482
diags.diagnose(loc, diag::conformance_availability_unavailable,
24762483
type, proto,
2477-
platform.empty(), platform, EncodedMessage.Message);
2484+
platform.empty(), platform, EncodedMessage.Message)
2485+
.limitBehavior(behavior);
24782486

24792487
switch (attr->getVersionAvailability(ctx)) {
24802488
case AvailableVersionComparison::Available:

test/Concurrency/require-explicit-sendable.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public struct S5 { } // no diagnostic: S5 is not Sendable
4545

4646
@available(*, unavailable)
4747
extension S5: Sendable { }
48+
// expected-note@-1{{conformance of 'S5' to 'Sendable' has been explicitly marked unavailable here}}
4849

4950
// Public type with a conditional conformance, so don't complain
5051
public struct S6<T, U> {
@@ -54,3 +55,18 @@ public struct S6<T, U> {
5455

5556
extension S6: Sendable where T: Sendable, U: Sendable { }
5657

58+
func acceptSendable<T: Sendable>(_: T) {
59+
}
60+
61+
struct S7 {
62+
}
63+
64+
@available(*, unavailable)
65+
extension S7: Sendable { }
66+
// expected-note@-1{{conformance of 'S7' to 'Sendable' has been explicitly marked unavailable here}}
67+
68+
69+
func testMe(s5: S5, s7: S7) {
70+
acceptSendable(s5) // expected-warning{{conformance of 'S5' to 'Sendable' is unavailable}}
71+
acceptSendable(s7) // expected-warning{{conformance of 'S7' to 'Sendable' is unavailable}}
72+
}

0 commit comments

Comments
 (0)