0

Compiler provides error message Type 'A' does not conform to protocol 'Equatable''

Why? The extension on the Accessible protocol should provides Equatable conformance, no?

struct A: Equatable {
    var simp: any Accessible
}


protocol Accessible: Equatable {
    var accessToken: String {get set}
}

extension Accessible {
    static func ==(lhs: Self, rhs: Self) -> Bool {
        return lhs.accessToken == rhs.accessToken}
}
Small Talk
  • 747
  • 1
  • 6
  • 15
  • Because Accessible is a protocol, not a real type, and protocols cannot conform to themselves? – matt Jan 03 '23 at 15:38
  • The property does not conform to Equatable. `any Accessible` does not itself conform to `Accessible`, and also does not conform to `Equatable`. Protocols do not conform to themselves (protocols never conform to protocols; they only can require other protocols). The Equatable protocol requires that two items of the same concrete type (not a protocol) have an `==`. – Rob Napier Jan 03 '23 at 15:46
  • While it's a bit of head-scratcher, maybe the easiest way for me to internalize it is simply that one protocol can't conform to another. I won't ask why. If that's the case, shouldn't it be easy enough for the compiler to detect that invalid construction, and throw an error? – Small Talk Jan 03 '23 at 18:04
  • It does. It's the error you've put in the question... – flanker Jan 07 '23 at 20:44

0 Answers0