D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11998 - writeln with string enum outputs the enum name, not the string
Summary: writeln with string enum outputs the enum name, not the string
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-25 17:08 UTC by Martin Nowak
Modified: 2015-06-09 01:31 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2014-01-25 17:08:01 UTC
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 bearophile_hugs 2014-01-25 17:16:39 UTC
At best this is an enhancement request. But you are asking to add to make a special case for string enums.
Comment 2 Peter Alexander 2014-01-27 12:41:31 UTC
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 Martin Nowak 2014-01-27 14:23:35 UTC
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