Bug 11998 – writeln with string enum outputs the enum name, not the string

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-25T17:08:00Z
Last change time
2015-06-09T01:31:14Z
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2014-01-25T17:08:01Z
cat > bug.d << CODE enum Enum : string { member = "printThis", } void main() { import std.stdio : writeln; writeln(member); } CODE dmd -run bug ---- Output is 'member' instead of 'printThis'. See http://dpaste.dzfl.pl/e801e755 ----
Comment #1 by bearophile_hugs — 2014-01-25T17:16:39Z
At best this is an enhancement request. But you are asking to add to make a special case for string enums.
Comment #2 by peter.alexander.au — 2014-01-27T12:41:31Z
I think this is by design. The EnumBaseType just indicates that the enum values can be implicitly converted to the EnumBaseType. It's not the same as `enum string member = "printThis";` I'm not a fan of special casing the output of string enums.
Comment #3 by code — 2014-01-27T14:23:35Z
Maybe I was too fast with this, I just expected a different result. With anonymous enums it works btw. enum name1 = "printThis"; enum { name2 = "foo", name3 = "bar", } void main() { import std.stdio : writeln; writeln(name1, name2, name3); } http://dpaste.dzfl.pl/39b780cc