savi icon indicating copy to clipboard operation
savi copied to clipboard

Add compiler error for duplicate enum values

Open jemc opened this issue 3 years ago • 1 comments

In an :enum, we should raise an error if any two :member declarations have the same value.

Open Question:

  • [ ] Should there be an allowed way to intentionally have another alias :member for the same value (such as in the case of a library wanting to change the name of a member while temporarily keeping deprecated support for the old name)?

jemc avatar Mar 26 '22 01:03 jemc

Would :alias work in this case?

:enum Colors
  :member gray 1
  :member red 2

  :alias grey gray

And what about exhaustiveness checks? Given two members of the same enum value, would exhaustiveness check still succeed when only using one of the members? E.g.

:enum Colors
  :member gray 1
  :member grey 1
  :member red 2

// I am assuming exhaustivness checks here...
case color == (
  | Colors.gray | 
    ... 
  | Colors.red |
    ...
  |
    unreachable
)

mneumann avatar Mar 30 '22 12:03 mneumann