No we should not support enum types derived from strings

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu May 13 02:43:41 UTC 2021


On Wednesday, May 12, 2021 8:13:04 PM MDT Jonathan M Davis via Digitalmars-d 
wrote:
> I've argued in the past that the language should disallow all operations on
> enums (aside from casts) which aren't guaranteed to result in a valid value
> for that enum type, but not everyone agrees with that stance.

Or more accurately, all operations on an enum which are not guaranteed to
result in a valid enum value should result in the base type (and thus not be
assignable to a variable of that enum type without a cast), and operations
which mutate the enum should not be allowed unless they're guaranteed to
result in a valid enum value. But regardless, the point is that ideally,
unless a cast is used, it should be impossible to have something typed as an
enum without it being guaranteed that the value be one of the enumerated
values for that enum type. But that's definitely not how D enums work...

- Jonathan M Davis





More information about the Digitalmars-d mailing list