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