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?

1 Like

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.

4 Likes

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

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.

2 Likes

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