Skip to content

Commit c165a2c

Browse files
committed
Sema: Error for potentially unavailable conformances in Swift 6.
Diagnostics about use of potentially unavailable conformances had to be downgraded to warnings in Swift 5 in order to preserve source compatibility. These diagnostics should be errors by default in Swift 6. Resolves rdar://88210812
1 parent baaa8f3 commit c165a2c

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6714,10 +6714,6 @@ ERROR(conformance_availability_only_version_newer, none,
67146714
"conformance of %0 to %1 is only available in %2 %3 or newer",
67156715
(Type, Type, StringRef, llvm::VersionTuple))
67166716

6717-
WARNING(conformance_availability_only_version_newer_warn, none,
6718-
"conformance of %0 to %1 is only available in %2 %3 or newer",
6719-
(Type, Type, StringRef, llvm::VersionTuple))
6720-
67216717
//------------------------------------------------------------------------------
67226718
// MARK: @discardableResult
67236719
//------------------------------------------------------------------------------

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,17 +2182,14 @@ void TypeChecker::diagnosePotentialUnavailability(
21822182
{
21832183
auto type = rootConf->getType();
21842184
auto proto = rootConf->getProtocol()->getDeclaredInterfaceType();
2185-
2186-
auto diagID = (ctx.LangOpts.EnableConformanceAvailabilityErrors
2187-
? diag::conformance_availability_only_version_newer
2188-
: diag::conformance_availability_only_version_newer_warn);
2189-
auto behavior = behaviorLimitForExplicitUnavailability(rootConf, dc);
2190-
auto err =
2191-
ctx.Diags.diagnose(
2192-
loc, diagID,
2193-
type, proto, prettyPlatformString(targetPlatform(ctx.LangOpts)),
2194-
reason.getRequiredOSVersionRange().getLowerEndpoint());
2195-
err.limitBehavior(behavior);
2185+
auto err = ctx.Diags.diagnose(
2186+
loc, diag::conformance_availability_only_version_newer, type, proto,
2187+
prettyPlatformString(targetPlatform(ctx.LangOpts)),
2188+
reason.getRequiredOSVersionRange().getLowerEndpoint());
2189+
2190+
err.warnUntilSwiftVersionIf(
2191+
!ctx.LangOpts.EnableConformanceAvailabilityErrors, 6);
2192+
err.limitBehavior(behaviorLimitForExplicitUnavailability(rootConf, dc));
21962193

21972194
// Direct a fixit to the error if an existing guard is nearly-correct
21982195
if (fixAvailabilityByNarrowingNearbyVersionCheck(loc, dc,

test/Sema/conformance_availability.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %target-typecheck-verify-swift -swift-version 5 -enable-conformance-availability-errors
2+
// RUN: %target-typecheck-verify-swift -swift-version 6
23

34
// REQUIRES: OS=macosx
5+
// REQUIRES: asserts
46

57
public protocol Horse {}
68
func takesHorse<T : Horse>(_: T) {}

test/Sema/conformance_availability_warn.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ extension HasAvailableConformance1 : Horse {}
2525
// example but with this flag.
2626

2727
func passAvailableConformance1(x: HasAvailableConformance1) { // expected-note 6{{add @available attribute to enclosing global function}}
28-
takesHorse(x) // expected-warning {{conformance of 'HasAvailableConformance1' to 'Horse' is only available in macOS 100 or newer}}
28+
takesHorse(x) // expected-warning {{conformance of 'HasAvailableConformance1' to 'Horse' is only available in macOS 100 or newer; this is an error in Swift 6}}
2929
// expected-note@-1 {{add 'if #available' version check}}
3030

31-
takesHorseExistential(x) // expected-warning {{conformance of 'HasAvailableConformance1' to 'Horse' is only available in macOS 100 or newer}}
31+
takesHorseExistential(x) // expected-warning {{conformance of 'HasAvailableConformance1' to 'Horse' is only available in macOS 100 or newer; this is an error in Swift 6}}
3232
// expected-note@-1 {{add 'if #available' version check}}
3333

34-
x.giddyUp() // expected-warning {{conformance of 'HasAvailableConformance1' to 'Horse' is only available in macOS 100 or newer}}
34+
x.giddyUp() // expected-warning {{conformance of 'HasAvailableConformance1' to 'Horse' is only available in macOS 100 or newer; this is an error in Swift 6}}
3535
// expected-note@-1 {{add 'if #available' version check}}
3636

37-
_ = x.isGalloping // expected-warning {{conformance of 'HasAvailableConformance1' to 'Horse' is only available in macOS 100 or newer}}
37+
_ = x.isGalloping // expected-warning {{conformance of 'HasAvailableConformance1' to 'Horse' is only available in macOS 100 or newer; this is an error in Swift 6}}
3838
// expected-note@-1 {{add 'if #available' version check}}
3939

40-
_ = x[keyPath: \.isGalloping] // expected-warning {{conformance of 'HasAvailableConformance1' to 'Horse' is only available in macOS 100 or newer}}
40+
_ = x[keyPath: \.isGalloping] // expected-warning {{conformance of 'HasAvailableConformance1' to 'Horse' is only available in macOS 100 or newer; this is an error in Swift 6}}
4141
// expected-note@-1 {{add 'if #available' version check}}
4242

43-
_ = UsesHorse<HasAvailableConformance1>.self // expected-warning {{conformance of 'HasAvailableConformance1' to 'Horse' is only available in macOS 100 or newer}}
43+
_ = UsesHorse<HasAvailableConformance1>.self // expected-warning {{conformance of 'HasAvailableConformance1' to 'Horse' is only available in macOS 100 or newer; this is an error in Swift 6}}
4444
// expected-note@-1 {{add 'if #available' version check}}
4545
}
4646

0 commit comments

Comments
 (0)