DIPX: Enum Literals / Implicit Selector Expression

Ogi ogion.art at gmail.com
Thu Jun 30 09:08:30 UTC 2022


On Thursday, 2 December 2021 at 19:44:07 UTC, russhy wrote:
>
I was always wondering why this doesn’t “just work” in D:

```D
enum Color { red, orange }
Color color = orange;
```

This is a major source of frustration when porting from C, where 
enum assignment does work like this (but, unlike in D, enum 
member names must be unique).

Usually D compiler is smart enough to evaluate the type of the 
right-hand of an assignment. But for some reason it’s not the 
case with enums. I was under impression that this is a deliberate 
(although questionable) design to avoid some bugs rather some 
technical limitation.


More information about the Digitalmars-d mailing list