Skip to content

Commit 899f785

Browse files
committed
[Concurrency] Downgrade preconcurrency errors about unavailable conformances
to `Sendable`. (cherry picked from commit 7331c5e)
1 parent 65c06c7 commit 899f785

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,7 +2848,8 @@ bool swift::diagnoseExplicitUnavailability(SourceLoc loc,
28482848
const RootProtocolConformance *rootConf,
28492849
const ExtensionDecl *ext,
28502850
const ExportContext &where,
2851-
bool warnIfConformanceUnavailablePreSwift6) {
2851+
bool warnIfConformanceUnavailablePreSwift6,
2852+
bool preconcurrency) {
28522853
auto *attr = AvailableAttr::isUnavailable(ext);
28532854
if (!attr)
28542855
return false;
@@ -2909,7 +2910,7 @@ bool swift::diagnoseExplicitUnavailability(SourceLoc loc,
29092910
diags.diagnose(loc, diag::conformance_availability_unavailable,
29102911
type, proto,
29112912
platform.empty(), platform, EncodedMessage.Message)
2912-
.limitBehaviorUntilSwiftVersion(behavior, 6)
2913+
.limitBehaviorWithPreconcurrency(behavior, preconcurrency)
29132914
.warnUntilSwiftVersionIf(warnIfConformanceUnavailablePreSwift6, 6);
29142915

29152916
switch (attr->getVersionAvailability(ctx)) {
@@ -4499,7 +4500,8 @@ swift::diagnoseConformanceAvailability(SourceLoc loc,
44994500
}
45004501

45014502
if (diagnoseExplicitUnavailability(loc, rootConf, ext, where,
4502-
warnIfConformanceUnavailablePreSwift6)) {
4503+
warnIfConformanceUnavailablePreSwift6,
4504+
preconcurrency)) {
45034505
maybeEmitAssociatedTypeNote();
45044506
return true;
45054507
}

lib/Sema/TypeCheckAvailability.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ bool diagnoseExplicitUnavailability(
276276
const RootProtocolConformance *rootConf,
277277
const ExtensionDecl *ext,
278278
const ExportContext &where,
279-
bool warnIfConformanceUnavailablePreSwift6 = false);
279+
bool warnIfConformanceUnavailablePreSwift6 = false,
280+
bool preconcurrency = false);
280281

281282
/// Diagnose uses of the runtime support of the given type, such as
282283
/// type metadata and dynamic casting.

test/Concurrency/predates_concurrency_swift6.swift

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

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

185+
class UnavailableSendable {}
186+
187+
@available(*, unavailable)
188+
extension UnavailableSendable: @unchecked Sendable {}
189+
// expected-note@-1 4 {{conformance of 'UnavailableSendable' to 'Sendable' has been explicitly marked unavailable here}}
190+
185191
typealias T = RequireSendable<NotSendable>
186192
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
187193

188-
func testRequirementDowngrade(ns: NotSendable) {
194+
typealias T2 = RequireSendable<UnavailableSendable>
195+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
196+
197+
func testRequirementDowngrade(ns: NotSendable, us: UnavailableSendable) {
189198
requireSendable(ns)
190199
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
200+
201+
requireSendable(us)
202+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
191203
}
192204

193205

194206
protocol P2 {}
195207

196208
extension NotSendable: P2 {}
197209

210+
extension UnavailableSendable: P2 {}
211+
198212
@preconcurrency
199213
func requireSendableExistential(_: any P2 & Sendable) {}
200214

201215
func requireSendableExistentialAlways(_: any P2 & Sendable) {}
202216

203-
func testErasureDowngrade(ns: NotSendable) {
217+
func testErasureDowngrade(ns: NotSendable, us: UnavailableSendable) {
204218
requireSendableExistential(ns)
205219
// expected-warning@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
206220

221+
requireSendableExistential(us)
222+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
223+
207224
withSendableClosure {
208225
let ns = NotSendable()
209226
requireSendableExistentialAlways(ns)
210227
// expected-error@-1 {{type 'NotSendable' does not conform to the 'Sendable' protocol}}
228+
229+
let us = UnavailableSendable()
230+
requireSendableExistentialAlways(us)
231+
// expected-error@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
211232
}
212233
}

0 commit comments

Comments
 (0)