Open
Description
Description
When synthesizing conformance (at least to Equatable and Hashable), the compiler ignores the availability of conformances on constituent properties.
I discovered this because in the Xcode 16 SDK, CGSize has a conformance to Hashable that's only available from iOS 18.
Reproduction
struct S {}
@available(macOS 90, *)
extension S: Equatable {
static func == (lhs: S, rhs: S) -> Bool {
if #available(macOS 90, *) {
true
} else {
fatalError("this function does not exist")
}
}
}
struct T: Equatable {
var s: S
}
_ = T(s: S()) == T(s: S())
$ swiftc -swift-version 6 ConditionalConformanceBackDeploy.swift
ConditionalConformanceBackDeploy.swift:6:12: warning: unnecessary check for 'macOS'; enclosing scope ensures guard will always be true
2 |
3 | @available(macOS 90, *)
4 | extension S: Equatable {
| `- note: enclosing scope here
5 | static func == (lhs: S, rhs: S) -> Bool {
6 | if #available(macOS 90, *) {
| `- warning: unnecessary check for 'macOS'; enclosing scope ensures guard will always be true
7 | true
8 | } else {
$ ./ConditionalConformanceBackDeploy
ConditionalConformanceBackDeploy/ConditionalConformanceBackDeploy.swift:9: Fatal error: this function does not exist
zsh: trace trap ./ConditionalConformanceBackDeploy
Expected behavior
Ideally, I guess the synthesized conformance would also get synthesized availability, intersecting the availabilities of all the constituent properties.
I'd also accept that the conformance simply cannot be synthesized where the availability of its type/extension doesn't match/exceed the availability of the constituent properties
Environment
swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.0
(Xcode 16.0)
Additional information
No response