Explicit casting of enum -- intentional restriction?

rcorre via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Oct 2 05:00:05 PDT 2016


On Sunday, 2 October 2016 at 10:52:59 UTC, Marc Schütz wrote:
> On Saturday, 1 October 2016 at 20:52:48 UTC, rcorre wrote:
>> I just tried to compile an old project and the following 
>> failed:
>>
>> ---
>> enum Paths : string {
>>   bitmapDir     = "content/image",
>>   fontDir       = "content/font",
>>   soundDir      = "content/sound",
>> ...
>>
>> if (Paths.preferences.exists)
>>     ...
>> ---
>>
>> It turns out members of Paths are no longer implicitly 
>> converted to string, and I needed to use
>>
>> if ((cast(string)Paths.preferences).exists)
>>
>> Is this an intentional limitation or a regression? I didn't 
>> see it in the last few changelogs but I'll admit I didn't 
>> check them rigorously.
>
> This is the PR that broke it:
> https://github.com/dlang/phobos/pull/3447

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.


More information about the Digitalmars-d-learn mailing list