www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11998] New: writeln with string enum outputs the enum name, not the string

reply d-bugmail puremagic.com writes:
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



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: -------
Jan 25 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11998


bearophile_hugs eml.cc changed:

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



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: -------
Jan 25 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jan 27 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11998




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: -------
Jan 27 2014
prev sibling parent d-bugmail puremagic.com writes:
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: -------
Jan 27 2014