Skip to content

Commit a87fdfc

Browse files
authored
Merge pull request #73697 from hborla/6.0-opaque-type-conformance-availability
[6.0][Availability] Diagnose unavailable conformances in `UnderlyingToOpaqueExpr`.
2 parents 4b7d6b3 + b35e4a6 commit a87fdfc

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2896,7 +2896,7 @@ bool swift::diagnoseExplicitUnavailability(SourceLoc loc,
28962896
diags.diagnose(loc, diag::conformance_availability_unavailable,
28972897
type, proto,
28982898
platform.empty(), platform, EncodedMessage.Message)
2899-
.limitBehavior(behavior)
2899+
.limitBehaviorUntilSwiftVersion(behavior, 6)
29002900
.warnUntilSwiftVersionIf(warnIfConformanceUnavailablePreSwift6, 6);
29012901

29022902
switch (attr->getVersionAvailability(ctx)) {
@@ -3454,6 +3454,11 @@ class ExprAvailabilityWalker : public ASTWalker {
34543454
}
34553455
}
34563456

3457+
if (auto UTO = dyn_cast<UnderlyingToOpaqueExpr>(E)) {
3458+
diagnoseSubstitutionMapAvailability(
3459+
UTO->getLoc(), UTO->substitutions, Where);
3460+
}
3461+
34573462
if (auto ME = dyn_cast<MacroExpansionExpr>(E)) {
34583463
diagnoseDeclRefAvailability(
34593464
ME->getMacroRef(), ME->getMacroNameLoc().getSourceRange());

test/Concurrency/sendable_checking.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,15 @@ extension ImplicitSendableViaMain {
427427
struct TestImplicitSendable: Sendable {
428428
var x: ImplicitSendableViaMain
429429
}
430+
431+
struct UnavailableSendable {}
432+
433+
@available(*, unavailable)
434+
extension UnavailableSendable: Sendable {}
435+
// expected-note@-1 {{conformance of 'UnavailableSendable' to 'Sendable' has been explicitly marked unavailable here}}
436+
437+
@available(SwiftStdlib 5.1, *)
438+
func checkOpaqueType() -> some Sendable {
439+
UnavailableSendable()
440+
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable; this is an error in the Swift 6 language mode}}
441+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -emit-sil -swift-version 6 %s -o /dev/null -verify
2+
3+
// REQUIRES: concurrency
4+
5+
6+
struct UnavailableSendable {}
7+
8+
@available(*, unavailable)
9+
extension UnavailableSendable: Sendable {}
10+
// expected-note@-1 {{conformance of 'UnavailableSendable' to 'Sendable' has been explicitly marked unavailable here}}
11+
12+
@available(SwiftStdlib 5.1, *)
13+
func checkOpaqueType() -> some Sendable {
14+
UnavailableSendable()
15+
// expected-error@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
16+
}

test/Sema/availability.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,14 @@ struct DeferBody {
169169
}
170170
}
171171

172+
struct NotP {}
173+
174+
protocol P {}
175+
176+
@available(*, unavailable)
177+
extension NotP: P {} // expected-note {{conformance of 'NotP' to 'P' has been explicitly marked unavailable here}}
178+
179+
@available(SwiftStdlib 5.1, *)
180+
func requireP() -> some P {
181+
NotP() // expected-error {{conformance of 'NotP' to 'P' is unavailable}}
182+
}

0 commit comments

Comments
 (0)