Skip to content

Commit 7331c5e

Browse files
committed
[Concurrency] Downgrade preconcurrency errors about unavailable conformances
to `Sendable`.
1 parent 806de5a commit 7331c5e

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ concreteSyntaxDeclForAvailableAttribute(const Decl *AbstractSyntaxDecl);
5353
static bool diagnoseExplicitUnavailability(
5454
SourceLoc loc, const RootProtocolConformance *rootConf,
5555
const ExtensionDecl *ext, const ExportContext &where,
56-
bool warnIfConformanceUnavailablePreSwift6 = false);
56+
bool warnIfConformanceUnavailablePreSwift6 = false,
57+
bool preconcurrency = false);
5758

5859
/// Emit a diagnostic for references to declarations that have been
5960
/// marked as unavailable, either through "unavailable" or "obsoleted:".
@@ -2986,7 +2987,8 @@ getExplicitUnavailabilityDiagnosticInfo(const Decl *decl,
29862987
bool diagnoseExplicitUnavailability(
29872988
SourceLoc loc, const RootProtocolConformance *rootConf,
29882989
const ExtensionDecl *ext, const ExportContext &where,
2989-
bool warnIfConformanceUnavailablePreSwift6) {
2990+
bool warnIfConformanceUnavailablePreSwift6,
2991+
bool preconcurrency) {
29902992
// Invertible protocols are never unavailable.
29912993
if (rootConf->getProtocol()->getInvertibleProtocolKind())
29922994
return false;
@@ -3012,7 +3014,7 @@ bool diagnoseExplicitUnavailability(
30123014
diags
30133015
.diagnose(loc, diag::conformance_availability_unavailable, type, proto,
30143016
platform.empty(), platform, EncodedMessage.Message)
3015-
.limitBehaviorUntilSwiftVersion(behavior, 6)
3017+
.limitBehaviorWithPreconcurrency(behavior, preconcurrency)
30163018
.warnUntilSwiftVersionIf(warnIfConformanceUnavailablePreSwift6, 6);
30173019

30183020
switch (diagnosticInfo->getStatus()) {
@@ -4641,7 +4643,8 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
46414643
// FIXME: diagnoseExplicitUnavailability() should take unmet requirement
46424644
if (diagnoseExplicitUnavailability(
46434645
loc, rootConf, ext, where,
4644-
warnIfConformanceUnavailablePreSwift6)) {
4646+
warnIfConformanceUnavailablePreSwift6,
4647+
preconcurrency)) {
46454648
maybeEmitAssociatedTypeNote();
46464649
return true;
46474650
}

test/Concurrency/predates_concurrency_swift6.swift

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,31 +200,52 @@ struct RequireSendable<T: Sendable> {}
200200

201201
class NotSendable {} // expected-note 4 {{class 'NotSendable' does not conform to the 'Sendable' protocol}}
202202

203+
class UnavailableSendable {}
204+
205+
@available(*, unavailable)
206+
extension UnavailableSendable: @unchecked Sendable {}
207+
// expected-note@-1 4 {{conformance of 'UnavailableSendable' to 'Sendable' has been explicitly marked unavailable here}}
208+
203209
typealias T = RequireSendable<NotSendable>
204210
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
205211

206-
func testRequirementDowngrade(ns: NotSendable) {
212+
typealias T2 = RequireSendable<UnavailableSendable>
213+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
214+
215+
func testRequirementDowngrade(ns: NotSendable, us: UnavailableSendable) {
207216
requireSendable(ns)
208217
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
218+
219+
requireSendable(us)
220+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
209221
}
210222

211223

212224
protocol P2 {}
213225

214226
extension NotSendable: P2 {}
215227

228+
extension UnavailableSendable: P2 {}
229+
216230
@preconcurrency
217231
func requireSendableExistential(_: any P2 & Sendable) {}
218232

219233
func requireSendableExistentialAlways(_: any P2 & Sendable) {}
220234

221-
func testErasureDowngrade(ns: NotSendable) {
235+
func testErasureDowngrade(ns: NotSendable, us: UnavailableSendable) {
222236
requireSendableExistential(ns)
223237
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
224238

239+
requireSendableExistential(us)
240+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
241+
225242
withSendableClosure {
226243
let ns = NotSendable()
227244
requireSendableExistentialAlways(ns)
228245
// expected-error@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
246+
247+
let us = UnavailableSendable()
248+
requireSendableExistentialAlways(us)
249+
// expected-error@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
229250
}
230251
}

0 commit comments

Comments
 (0)