Iâm fine with the idea of having aliases - they can be useful at times, for sure. Especially when using enums to model existing, real-life stuff where there often already exists aliasing whether implicitly or explicitly.
But, how would this behave re. exhaustivity checks? Do they go based on the nominal cases or their values? Logically it has to be the latter - at runtime the enum is ultimately just a value, and if you allow two named cases to have an identical value, they are indistinguishable at runtime. That smells bad.
For example, what if a coder writes:
enum MouseButton: Int {
case _1, _2, _3, _4, _5, _6, _7, _8
case last = _8, left = _1, right = _2, middle = _3
}
âŚ
switch button {
case ._1:
// Do one thing
case .left:
// Do another thing
âŚ
}
Now what? Logically that has to be a compiler error. Solvable, but scrutiny is warranted any time the language introduces a new way to construct an invalid scenario.
The existing best approach for this - of static properties as @SDGGiesbrecht suggests - seems like the better approach. Itâs only annoyance currently is that enums donât allow you to define constants, i.e. use let, which is important both semantically to the user (itâs a constant, not a variable) but also presumably to the compiler, so that it can ultimately generate equally optimal code if you use one of those aliases vs the ârawâ case. (alternatively, today, you can define these aliases as constants outside the enum, in a context where let is allowed, but doing so has poor cohesion)
So I think what this is ultimately really wanting is just the relative minor addition of support for let attributes on enums�