Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0][Availability] Diagnose unavailable conformances in UnderlyingToOpaqueExpr. #73697

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2896,7 +2896,7 @@ bool swift::diagnoseExplicitUnavailability(SourceLoc loc,
diags.diagnose(loc, diag::conformance_availability_unavailable,
type, proto,
platform.empty(), platform, EncodedMessage.Message)
.limitBehavior(behavior)
.limitBehaviorUntilSwiftVersion(behavior, 6)
.warnUntilSwiftVersionIf(warnIfConformanceUnavailablePreSwift6, 6);

switch (attr->getVersionAvailability(ctx)) {
Expand Down Expand Up @@ -3454,6 +3454,11 @@ class ExprAvailabilityWalker : public ASTWalker {
}
}

if (auto UTO = dyn_cast<UnderlyingToOpaqueExpr>(E)) {
diagnoseSubstitutionMapAvailability(
UTO->getLoc(), UTO->substitutions, Where);
}

if (auto ME = dyn_cast<MacroExpansionExpr>(E)) {
diagnoseDeclRefAvailability(
ME->getMacroRef(), ME->getMacroNameLoc().getSourceRange());
Expand Down
12 changes: 12 additions & 0 deletions test/Concurrency/sendable_checking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,15 @@ extension ImplicitSendableViaMain {
struct TestImplicitSendable: Sendable {
var x: ImplicitSendableViaMain
}

struct UnavailableSendable {}

@available(*, unavailable)
extension UnavailableSendable: Sendable {}
// expected-note@-1 {{conformance of 'UnavailableSendable' to 'Sendable' has been explicitly marked unavailable here}}

@available(SwiftStdlib 5.1, *)
func checkOpaqueType() -> some Sendable {
UnavailableSendable()
// expected-warning@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable; this is an error in the Swift 6 language mode}}
}
16 changes: 16 additions & 0 deletions test/Concurrency/sendable_checking_swift6.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %target-swift-frontend -emit-sil -swift-version 6 %s -o /dev/null -verify

// REQUIRES: concurrency


struct UnavailableSendable {}

@available(*, unavailable)
extension UnavailableSendable: Sendable {}
// expected-note@-1 {{conformance of 'UnavailableSendable' to 'Sendable' has been explicitly marked unavailable here}}

@available(SwiftStdlib 5.1, *)
func checkOpaqueType() -> some Sendable {
UnavailableSendable()
// expected-error@-1 {{conformance of 'UnavailableSendable' to 'Sendable' is unavailable}}
}
11 changes: 11 additions & 0 deletions test/Sema/availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,14 @@ struct DeferBody {
}
}

struct NotP {}

protocol P {}

@available(*, unavailable)
extension NotP: P {} // expected-note {{conformance of 'NotP' to 'P' has been explicitly marked unavailable here}}

@available(SwiftStdlib 5.1, *)
func requireP() -> some P {
NotP() // expected-error {{conformance of 'NotP' to 'P' is unavailable}}
}