Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compiler error for duplicate enum values #275

Open
1 task
jemc opened this issue Mar 26, 2022 · 1 comment
Open
1 task

Add compiler error for duplicate enum values #275

jemc opened this issue Mar 26, 2022 · 1 comment
Labels
kind: feature: compiler Adding a new compiler feature or platform target needs design Need to work out a reasonably solid plan before we start doing this.

Comments

@jemc
Copy link
Contributor

jemc commented Mar 26, 2022

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 jemc added needs design Need to work out a reasonably solid plan before we start doing this. kind: feature: language Adding a new language feature kind: feature: compiler Adding a new compiler feature or platform target and removed kind: feature: language Adding a new language feature labels Mar 26, 2022
@mneumann
Copy link
Contributor

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
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature: compiler Adding a new compiler feature or platform target needs design Need to work out a reasonably solid plan before we start doing this.
Projects
None yet
Development

No branches or pull requests

2 participants