Skip to content

Commit 04ec243

Browse files
tayloraswifttkremenek
authored andcommitted
clarify lexicographic behavior when comparing enums with associated values (swiftlang#1117)
1 parent 31f954b commit 04ec243

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

proposals/0266-synthesized-comparable-for-enumerations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ enum Membership: Comparable {
9797

9898
## Proposed solution
9999

100-
Enumeration types which opt-in to a synthesized `Comparable` conformance would compare according to case declaration order, with later cases comparing greater than earlier cases. Only `enum` types with no associated values and `enum` types with only `Comparable` associated values would be eligible for synthesized conformances. No `enum` types with raw values would qualify.
100+
Enumeration types which opt-in to a synthesized `Comparable` conformance would compare according to case declaration order, with later cases comparing greater than earlier cases. Only `enum` types with no associated values and `enum` types with only `Comparable` associated values would be eligible for synthesized conformances. The latter kind of `enum`s will compare by case declaration order first, and then lexicographically by payload values. No `enum` types with raw values would qualify.
101101

102102
While basing behavior off of declaration order is unusual for Swift, as we generally hew to the “all fields are reorderable by the compiler” principle, it is not a foreign concept to `enums`. For example, reordering cases in a numeric-backed raw `enum` already changes its runtime behavior, since the case declaration order is taken to be meaningful in that context. I also believe that `enum` cases and `struct`/`class` fields are sufficiently distinct concepts that making enumeration case order meaningful would not make the language incoherent.
103103

0 commit comments

Comments
 (0)