Enum literals, good? bad? what do you think?

Dukc ajieskola at gmail.com
Thu Jul 22 14:05:53 UTC 2021


On Thursday, 22 July 2021 at 03:28:44 UTC, Paul Backus wrote:
> ```d
> enum E : string { x = "y", y = "x" }
>
> E e = "y"; // what happens here?
> ```

The VRP mechanics do not currently let that compile, so nothing 
will break. it would be equal to `E e = E.y`; `E e = cast(E)"y"` 
on the other hand would still be `E e = E.x`, as it's now.

Now, I admit that difference between implicit and explicit cast 
is confusing and a weakness.  Maybe the syntax should be `E e = 
".y"` instead to avoid the difference in behaviour between 
implicit and explicit cast.


More information about the Digitalmars-d mailing list