[Accepted] SE-0266: Synthesized Comparable conformance for enum types

The review for SE-0266 has ended and the proposal has been accepted.

The proposal was received positively, and removes boilerplate code for many common cases.

Concern was raised by some reviewers regarding the implicit reliance on source ordering to synthesize the conformance. The core team feels this behavior is justified based on several factors:

  • other features currently expose source ordering for enums (CaseIterable order and rawValue assignment).
  • < implementations on enums can easily be written in a way where adding new cases may not break compilation; comparable conformance must always be considered when adding cases even today.
  • conforming a type to a protocol requires an understanding of what that conformance means and how it is being fulfilled. "It compiles" is never enough.

Much of the review was occupied with discussion of adding support for structs and raw-representable enums. The core team would welcome further pitches weighing the pros and cons of these additions.


Are you considering the suggestion from the review thread to suspend synthesis if the type manually conforms to CaseIterable? Maybe have a warning?


That suggestion came after the decision to accept was made (and after the review period had ended, not that that is a particularly hard line we hold). My suggestion is that that be pitched as a proposed amendment to the accepted proposal, which we could then run a review for. That could potentially be folded into a proposal to make other additions to Comparable synthesis.


So in Version 1, we can declare Comparable and CaseIterable, but manually define exactly one of them, and then we have to live with the risk that the user's order isn't consistent with the automatic one. But if we do add the ban in Version 2, it would automatically be source breaking. It probably does meet the standard of source-breaking-if-the-old-way-was-dangerous, but we should provide a warning to cushion the blow.

1 Like

Amendments are handled before the proposal is part of any release, so there are no backwards‐compatibility concerns. If your pitch and implementation don’t arrive until after that point, then you would be looking at a separate proposal that does need to weigh compatibility.


Although the original commenter, I don’t have the bandwidth to make this pitch, so another person who feels like it’s a good idea should feel free to pick it up and run with it through this process if desired.

Terms of Service

Privacy Policy

Cookie Policy