No we should not support enum types derived from strings

Paul Backus snarwin at gmail.com
Thu May 13 01:41:43 UTC 2021


On Thursday, 13 May 2021 at 01:16:42 UTC, Andrei Alexandrescu 
wrote:
> It seems you can do almost everything with an enum that you can 
> do with its base type. Keyword being "almost". For example,
>
> x ~= "asd";
>
> works whether x is a string or an enum based on string. However,
>
> x = x ~ "asd";
>
> works if x is a string and does not work if x is an enum 
> derived from string. Therefore, a function using that 
> expression works for strings but not for enum strings.

A template function, you mean? Because (as the rest of the post 
you quoted demonstrates) the LSP does not and has never applied 
(in D) to substitutions that involve different instantiations of 
the same template. If you explicitly instantiate `func!string`, 
then it will work exactly as the LSP dictates, but if you 
substitute `func!string(x)` with `func!E(x)`, you have no 
guarantee.

Granted, the fact that `x ~= "asd"` works and `x = x ~ "asd"` 
doesn't is definitely a bug.


More information about the Digitalmars-d mailing list