Open
Description
Description
Equality for tuples seems to get lost.
Steps to reproduce
Here are two examples that raise different error messages.
Example A:
protocol P {
associatedtype A: Hashable
associatedtype B: Hashable
typealias C = (A, B)
}
struct S<T: P>: Equatable {
// error: Type 'S<T>.Inner' does not conform to protocol 'Equatable'
struct Inner: Equatable {
let c: T.C
}
let inner: Inner
}
Workaround:
static func == (lhs: S<T>.Inner, rhs: S<T>.Inner) -> Bool {
lhs.c == rhs.c
}
Example B with Optional
that makes things worse:
protocol P {
associatedtype A: Hashable
associatedtype B: Hashable
typealias C = Optional<(A, B)>
}
struct S<T: P>: Equatable {
// error: Type '(T.A, T.B)' cannot conform to 'Equatable'
static func == (lhs: Self, rhs: Self) -> Bool {
lhs.c == rhs.c
}
let c: T.C
}
Workaround:
static func == (lhs: Self, rhs: Self) -> Bool {
lhs.c?.0 == rhs.c?.0 && lhs.c?.1 == rhs.c?.1
}
Expected behavior
Both examples should compile just fine without manual implication of the ==
function.
Environment
-
Swift compiler version info:
swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
Target: arm64-apple-macosx13.0 -
Xcode version info: Version 14.1 (14B47b)
-
Deployment target: iOS 15.0