digitalmars.D.learn - Explicit casting of enum -- intentional restriction?
- rcorre (16/16) Oct 01 2016 I just tried to compile an old project and the following failed:
- Namespace (17/17) Oct 01 2016 The Code below still works, so I guess it's some problem with the
- Marc =?UTF-8?B?U2Now7x0eg==?= (3/19) Oct 02 2016 This is the PR that broke it:
- rcorre (5/30) Oct 02 2016 Thanks for tracking that down. I think the bug is that a
- Jonathan M Davis via Digitalmars-d-learn (16/20) Oct 02 2016 I really don't think that it makes sense for isSomeString to be true for...
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.
Oct 01 2016
The Code below still works, so I guess it's some problem with the constraint of "exists". ---- import std.stdio; enum Foo { A = "B" } void test(string a) { } void main() { test(Foo.A); Foo.A.test(); } ----
Oct 01 2016
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
Oct 02 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: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 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
Oct 02 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
Oct 02 2016