No we should not support enum types derived from strings
deadalnix
deadalnix at gmail.com
Tue May 11 14:30:57 UTC 2021
On Tuesday, 11 May 2021 at 13:50:46 UTC, Andrei Alexandrescu
wrote:
> No it isn't.
>
> EnumString and String are reference types. A reference to an
> enum value does not convert to a reference to its
> representation. Very very very VERY different.
>
Here we hit at the core of the problem. A reference to a type B
that is a subtype of A is not a subtype of ref A. Or, in simlpler
terms, B is a subtype of A doesn't imply that ref B is a subtype
of ref A.
This means that you can pass a B where an A is expected, but not
a ref B where a ref A is expected.
You'll note that the example I provided with classes for
understanding will also demonstrate the same behavior:
class A { ... }
class B : A { ... }
void foo(ref A a) { ... }
B b = ...;
foo(b); // This must be an error because, while B is a subtype of
A, ref B is not a subtype of ref A.
That means that you shouldn't be able to pass SomeEnumString to
any function, in phobos or elsewhere, that will mutate it, such
as popFront. But you should be able to do so, transparently, so
any function that won't. That includes all compile time
parameters.
More information about the Digitalmars-d
mailing list