No we should not support enum types derived from strings

deadalnix deadalnix at gmail.com
Thu May 13 12:28:19 UTC 2021


On Thursday, 13 May 2021 at 02:43:41 UTC, Jonathan M Davis wrote:
> 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

YES!


More information about the Digitalmars-d mailing list