No we should not support enum types derived from strings
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon May 10 04:21:34 UTC 2021
On 5/9/21 8:57 PM, deadalnix wrote:
> On Friday, 7 May 2021 at 16:43:20 UTC, Andrei Alexandrescu wrote:
>> Well you see here is the problem. An enum with base string can be
>> coerced to a string, but is not a true subtype of string. This came to
>> a head with ranges, too - you can pop off the head of a string still
>> have a string, but if you pop off the head of an enum string you get
>> some enum value that is not present in the set of enum values.
>> Concatenation has similar problems, e.g. s ~ s for enum strings yields
>> string, not an enum string. (Weirdly s ~= s works...)
>>
>
> Popping the head out of an enum value ought to be a string, not that
> enum's value. I don't really see where the problem is here, this is
> subtyping 101.
So you have a range r of type T.
You call r.popFront().
Obvioulsly the type of r should stay the same because in D variables
don't change type.
So... what gives, young Padawan?
No, this is not subtyping 101.
More information about the Digitalmars-d
mailing list