Thread overview
[Issue 11998] New: writeln with string enum outputs the enum name, not the string
Jan 26, 2014
Martin Nowak
Jan 27, 2014
Peter Alexander
Jan 27, 2014
Martin Nowak
Jan 27, 2014
Martin Nowak
January 26, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11998

           Summary: writeln with string enum outputs the enum name, not
                    the string
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: code@dawg.eu


--- Comment #0 from Martin Nowak <code@dawg.eu> 2014-01-25 17:08:01 PST ---
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
----

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 26, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11998


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #1 from bearophile_hugs@eml.cc 2014-01-25 17:16:39 PST ---
At best this is an enhancement request. But you are asking to add to make a special case for string enums.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 27, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11998


Peter Alexander <peter.alexander.au@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter.alexander.au@gmail.co
                   |                            |m


--- Comment #2 from Peter Alexander <peter.alexander.au@gmail.com> 2014-01-27 12:41:31 PST ---
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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 27, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11998



--- Comment #3 from Martin Nowak <code@dawg.eu> 2014-01-27 14:23:35 PST ---
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

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 27, 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11998


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID
           Severity|normal                      |enhancement


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------