www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1610] New: Enum.stringof is int, not the name of the enum

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1610

           Summary: Enum.stringof is int, not the name of the enum
           Product: D
           Version: 2.007
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: andrei metalanguage.com


import std.stdio;
enum ABC { a, b, c }
void main() { writeln(ABC.stringof); } // prints "int"

This causes major issues in reflective and serialization code. The .stringof
should evaluate to the name of the enum, e.g. "ABC".


-- 
Oct 24 2007
next sibling parent Ary Manzana <ary esperanto.org.ar> writes:
d-bugmail puremagic.com escribió:
 http://d.puremagic.com/issues/show_bug.cgi?id=1610
 
            Summary: Enum.stringof is int, not the name of the enum
            Product: D
            Version: 2.007
           Platform: PC
         OS/Version: Linux
             Status: NEW
           Severity: normal
           Priority: P2
          Component: DMD
         AssignedTo: bugzilla digitalmars.com
         ReportedBy: andrei metalanguage.com
 
 
 import std.stdio;
 enum ABC { a, b, c }
 void main() { writeln(ABC.stringof); } // prints "int"
 
 This causes major issues in reflective and serialization code. The .stringof
 should evaluate to the name of the enum, e.g. "ABC".
 
 

lol, I just discovered the same thing yesterday. I found out you can also do this: void foo() { int x = typeof(ABC).a; // same as ABC.a int y = typeof(ABC).init; // y = 0 } The compiler also allows me to do this: enum ABCInit { a, b, c, init } Now if I do: void foo() { int y = typeof(ABC).init; // y = 3 } So an addition of a field "init" could potentialy and silently introduce bugs in the application. Although I think it's rare that someone would want to define an "init" property for an enum type (or for a class, or struct), I think the compiler should disallow this (same behaviour as trying to redefine the "sizeof", "alignof", etc., properties).
Oct 24 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1610





------- Comment #2 from moritzwarning web.de  2008-07-22 12:51 -------
I have to deal with this problem in a template function that is used with a lot
of different enum types (by some other bigger templates). But not handled enum
types hit a static assert.
I wrote different template functions before but hit some limitations that
forced me to put everything in the same function using static ifs.

Because T.stringof is almost always "int", I have a hard time to find out what
enum is not handled.

I hope this problem will be addressed soon.


-- 
Jul 22 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1610


shro8822 vandals.uidaho.edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|Linux                       |All
            Version|2.007                       |1.033




------- Comment #3 from shro8822 vandals.uidaho.edu  2008-07-22 13:26 -------
this issue is also in latest V1 so switching the version to that


-- 
Jul 22 2008
prev sibling next sibling parent reply "Koroskin Denis" <2korden gmail.com> writes:
On Tue, 22 Jul 2008 22:26:13 +0400, <d-bugmail puremagic.com> wrote:

 http://d.puremagic.com/issues/show_bug.cgi?id=1610


 shro8822 vandals.uidaho.edu changed:

            What    |Removed                     |Added
 ----------------------------------------------------------------------------
          OS/Version|Linux                       |All
             Version|2.007                       |1.033




 ------- Comment #3 from shro8822 vandals.uidaho.edu  2008-07-22 13:26  
 -------
 this issue is also in latest V1 so switching the version to that

I thought version is meant to be the *earliest* version known to have the bug, not the latest one....
Jul 22 2008
parent reply BCS <ao pathlink.com> writes:
Reply to Koroskin,

 On Tue, 22 Jul 2008 22:26:13 +0400, <d-bugmail puremagic.com> wrote:
 
 http://d.puremagic.com/issues/show_bug.cgi?id=1610
 
 shro8822 vandals.uidaho.edu changed:
 
 What    |Removed                     |Added
 ---------------------------------------------------------------------
 -------
 OS/Version|Linux                       |All
 Version|2.007                       |1.033
 ------- Comment #3 from shro8822 vandals.uidaho.edu  2008-07-22 13:26
 -------
 this issue is also in latest V1 so switching the version to that

the bug, not the latest one....

Setting the version to the latest minor version shows active interest and that the bug hasn't magically disappeared. OTOH, IMHO the oldest major version that the bug should be fixed in should be tagged to indicate that.
Jul 22 2008
next sibling parent Bill Baxter <dnewsgroup billbaxter.com> writes:
BCS wrote:
 Reply to Koroskin,
 
 On Tue, 22 Jul 2008 22:26:13 +0400, <d-bugmail puremagic.com> wrote:

 http://d.puremagic.com/issues/show_bug.cgi?id=1610

 shro8822 vandals.uidaho.edu changed:

 What    |Removed                     |Added
 ---------------------------------------------------------------------
 -------
 OS/Version|Linux                       |All
 Version|2.007                       |1.033
 ------- Comment #3 from shro8822 vandals.uidaho.edu  2008-07-22 13:26
 -------
 this issue is also in latest V1 so switching the version to that

the bug, not the latest one....

Setting the version to the latest minor version shows active interest and that the bug hasn't magically disappeared. OTOH, IMHO the oldest major version that the bug should be fixed in should be tagged to indicate that.

You can show interest just by posting a comment saying "halloo! this bug has been around since version 0.123, and it's still there in 1.latest. Any chance for a fix?". --bb
Jul 22 2008
prev sibling parent reply Brad Roberts <braddr puremagic.com> writes:
Bill Baxter wrote:
 BCS wrote:
 Reply to Koroskin,

 On Tue, 22 Jul 2008 22:26:13 +0400, <d-bugmail puremagic.com> wrote:

 http://d.puremagic.com/issues/show_bug.cgi?id=1610

 shro8822 vandals.uidaho.edu changed:

 What    |Removed                     |Added
 ---------------------------------------------------------------------
 -------
 OS/Version|Linux                       |All
 Version|2.007                       |1.033
 ------- Comment #3 from shro8822 vandals.uidaho.edu  2008-07-22 13:26
 -------
 this issue is also in latest V1 so switching the version to that

the bug, not the latest one....

Setting the version to the latest minor version shows active interest and that the bug hasn't magically disappeared. OTOH, IMHO the oldest major version that the bug should be fixed in should be tagged to indicate that.

You can show interest just by posting a comment saying "halloo! this bug has been around since version 0.123, and it's still there in 1.latest. Any chance for a fix?". --bb

On the other hand, this is one of the few cases of changing the version that is probably a good idea. It was reported against 2.x and has been shifted over to 1.x. That it's not a 2.x specific bug is useful info. Otherwise, Bill is right. Do NOT shift a version number to a higher version just to show interest as thats not helpful. A ping and a note that it's still broken is sufficient. Later, Brad
Jul 22 2008
parent BCS <ao pathlink.com> writes:
Reply to Brad,

 On the other hand, this is one of the few cases of changing the
 version that is probably a good idea.  It was reported against 2.x and
 has been shifted over to 1.x.  That it's not a 2.x specific bug is
 useful info.
 
 Otherwise, Bill is right.  Do NOT shift a version number to a higher
 version just to show interest as thats not helpful.  A ping and a note
 that it's still broken is sufficient.
 
 Later,
 Brad

maybe there should be 4 versions [ :b ] reported and latest-verified for v1 and v2
Jul 22 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1610


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #4 from bugzilla digitalmars.com  2008-12-08 00:53 -------
Fixed in DMD 1.037 and 2.021


-- 
Dec 07 2008