Explicit casting of enum -- intentional restriction?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Oct 2 07:41:23 PDT 2016


On Sunday, October 02, 2016 12:00:05 rcorre via Digitalmars-d-learn wrote:
> Thanks for tracking that down. I think the bug is that a
> string-typed enum passes isSomeString but not isInputRange. It
> should either be both or neither. I filed
> https://issues.dlang.org/show_bug.cgi?id=16573.

I really don't think that it makes sense for isSomeString to be true for an
enum (I thought that we'd made it so that it wasn't, so the fact that it
currently is is quite surprising and definitely annoying). Making
isConvertibleToString true for enums (since for some reason, it's not) would
make exists work with enums again, but having both isSomeString and
isConvertibleToString be true for enums could be a problem.

I really think that making isSomeString false for enums with a base type of
string is what we would ideally do (that and make isConvertibleToString true
for those enums), but I'm not sure that we could get away with it at this
point, since there may be a fair bit of code in the wild depending on
isSomeString being true for enums with a base type of string. But the
situation with isInputString helps make it clear why treating an enum with a
base type of string as if it were a string rather than just convertible to
string is a problem.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list