Bug 12494 – Regression (2.064): to!string(enum) returns incorrect value

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-30T11:03:00Z
Last change time
2014-03-31T13:10:52Z
Assigned to
nobody
Creator
zan77137

Comments

Comment #0 by zan77137 — 2014-03-30T11:03:23Z
This code doesn't work: --------- main.d --------- enum E { a = 0, b = 0, c = 1, } void main() { import std.stdio, std.conv, std.string; assert(format("%s", E.c) == "c"); // main(11): OK assert(to!string(E.c) == "c"); // main(12): NG } --------- RESULT --------- $ dmd -run main core.exception.AssertError@main(12): Assertion failure --------- I think it is strange that to!string returns incorrect value though format returns correct value.
Comment #1 by monarchdodra — 2014-03-30T12:44:25Z
Thanks. I know what is causing this. Fixing ASAP.
Comment #2 by andrej.mitrovich — 2014-03-30T14:34:45Z
Comment #3 by andrej.mitrovich — 2014-03-30T14:36:57Z
(In reply to comment #1) > Thanks. I know what is causing this. Yeah, we went a bit overboard with avoiding allocations and ended up using indexing, but forgetting we're calling NoDuplicates when generating the switch/case.
Comment #4 by andrej.mitrovich — 2014-03-30T14:37:40Z
(In reply to comment #1) > Fixing ASAP. We could use __traits(getMember) unless you find another solution.
Comment #5 by andrej.mitrovich — 2014-03-30T14:38:38Z
(In reply to comment #2) > Similar but the opposite: > https://d.puremagic.com/issues/show_bug.cgi?id=10814 Oops I didn't want to post this.
Comment #6 by dlang-bugzilla — 2014-03-30T14:48:15Z
(In reply to comment #1) > Thanks. I know what is causing this. Fixing ASAP. Introduced in https://github.com/D-Programming-Language/phobos/pull/1565 in case anyone still wants to know
Comment #7 by github-bugzilla — 2014-03-31T13:10:19Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/78d84e515a7551fd7536595730abf943dc573c04 Fix Issue 12494 - to!string(enum) incorrect value https://github.com/D-Programming-Language/phobos/commit/7a94226a22c7ca3f6e997aeb2b18621dcfea5834 Merge pull request #2059 from monarchdodra/12494 Fix Issue 12494 - Regression (2.064): to!string(enum) returns incorrect value