Enum implements `==` without being Equatable


It does surprize me that this code runs:

enum Enum {
    case a, b, c, d

let value = Enum.a
print(value == .a) // true
print(value == .b) // false

Shouldn’t we need to conform Enum to be equatable first for it to have synthesized implementation?

(Xiaodi Wu) #2

An enum without associated values has implicit Equatable conformance. This has always been the case for all released versions of Swift. It has been maintained even after SE-0185 for backwards compatibility.


Is there any other implicit conformance? I thought we completely eradicated them.

(Xiaodi Wu) #4

An enum without associated values also conforms implicitly to Hashable. I'm not aware that we have eradicated any implicit conformances; those are the only two.


Somehow I have the mindset of no implicit conformance. :slight_smile: