D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8508 - std.traits.isSomeString no longer works with enums
Summary: std.traits.isSomeString no longer works with enums
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2012-08-04 14:20 UTC by Jonathan M Davis
Modified: 2015-06-09 05:14 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2012-08-04 14:20:31 UTC
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 2 github-bugzilla 2012-08-05 15:13:43 UTC
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