Bug 8508 – std.traits.isSomeString no longer works with enums

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-08-04T14:20:00Z
Last change time
2015-06-09T05:14:54Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
issues.dlang

Comments

Comment #0 by issues.dlang — 2012-08-04T14:20:31Z
This code passes with 2.059 but fails with 2.060: import std.traits; enum E : string { a = "hello" } static assert(isSomeString!(typeof(E.a))); void main() { } It's commit https://github.com/D-Programming-Language/phobos/commit/52462bec6ea846f30e8dac309d63ccb4101e8f0c which broke this. Kenji Hara argues that enums should be treated as strongly typed by std.traits, but the language itself doesn't do this. auto func(string s) {...} will accept E.a just fine, but no auto func(S)(S s) if(isSomeString!S) {...} will not. Kenji also points out that std.traits has not been consistent with regards to how it treats enums, and enum U : uint { a = 0 } static assert(isUnsigned!(typeof(U.a))); fails with both 2.059 and 2.060. I'd argue that it should pass as well. Needing to distinguish between an enum of a particular base type and that exact type is quite rare AFAIK (std.conv.to and std.format care but not a lot else). As such, I really think that we'd be better off if std.traits treats enums as their base types and let code which cares about whether a particular template argument is an enum or not check whether it's an enum - that's what is(T == enum) is for. As it stands, it's _very_ easy to break code which uses enums when templatizing a function which wasn't previously templatized, and std.traits is completely inconsistent with the language with regards to enums. This needs to be fixed.
Comment #1 by k.hara.pg — 2012-08-05T09:10:11Z
Comment #2 by github-bugzilla — 2012-08-05T15:13:43Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/5daf79cbe3df1803f8bdf66edd2d57094529e8b7 fix Issue 8508 - std.traits.isSomeString no longer works with enums https://github.com/D-Programming-Language/phobos/commit/f541d19e9c8392de211aa9aa8a3f0a7baee953f0 Merge pull request #739 from 9rnsr/fix8508 Issue 8508 - std.traits.isSomeString no longer works with enums