Bug 3308 – Enum.RED.stringof gives "Enum", not "Enum.RED"

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2009-09-08T19:29:00Z
Last change time
2015-06-09T01:26:48Z
Assigned to
nobody
Creator
echochamber

Comments

Comment #0 by echochamber — 2009-09-08T19:29:54Z
The sample code in ".stringof Property" section in property.html: ---- cut here ---- module test; import std.stdio; struct Foo { } enum Enum { RED } typedef int myint; void main() { writefln((1+2).stringof); // "1 + 2" writefln(Foo.stringof); // "Foo" writefln(test.Foo.stringof); // "test.Foo" writefln(int.stringof); // "int" writefln((int*[5][]).stringof); // "int*[5][]" writefln(Enum.RED.stringof); // "Enum.RED" writefln(test.myint.stringof); // "test.myint" writefln((5).stringof); // "5" } ---- cut here ---- (I added 'module' and 'import' to make it compilable.) Actual output: ---- cut here ---- 1 + 2 Foo Foo int int*[5u][] Enum myint 5 ---- cut here ---- - Enum.RED.stringof gives "Enum", not "Enum.RED". - Module name "test" is not output. - 5u instead of 5.
Comment #1 by jarrett.billingsley — 2009-09-08T19:49:46Z
I'm not sure if this is a duplicate of bug 2881 or if it's just closely related. Or if this has just been known for so long but somehow never reported. I always wonder why the compiler seems to hate enums in so many ways..
Comment #2 by bearophile_hugs — 2010-06-02T14:48:13Z
See also bug 4261
Comment #3 by damianday — 2012-07-07T08:32:14Z
The example now outputs: 1 + 2 Foo Foo int int*[5u][] cast(Enum)0 int 5 Note that I change typedef -> alias for compatability.
Comment #4 by andrej.mitrovich — 2013-01-26T18:52:20Z
I'm not very happy with Enum.RED.stringof printing "cast(enum)0", but other than that that page is now correct (as long as you compile with -d).