Thread overview
[Issue 2881] New: x.stringof returns typeof(x).stringof when x is an enum
Apr 22, 2009
d-bugmail
Jan 13, 2010
nfxjfg@gmail.com
Mar 14, 2010
Vladimir
Mar 14, 2010
nfxjfg@gmail.com
Apr 29, 2010
nfxjfg@gmail.com
Jun 02, 2010
Walter Bright
April 22, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2881

           Summary: x.stringof returns typeof(x).stringof when x is an enum
           Product: D
           Version: 1.041
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: cbkbbejeap@mailinator.com


-------------
enum Shapes
{
        Circle, Square
}

void main()
{
        int i;
        Shapes s;

        pragma(msg, i.stringof);
        pragma(msg, s.stringof);
}
-------------

Expected Output:
i
s

Actual Output:
i
Shapes

I'm not sure, but this might be related to the fix for #1610


-- 

January 13, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2881


nfxjfg@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #1 from nfxjfg@gmail.com 2010-01-13 08:38:27 PST ---
This bug is a blocker for me. Here's a trivial patch that fixes it.
Note that the stringof functionality in getProperty() isn't called; it just
isn't needed and produces the wrong result.
Dear Walter, if you don't accept this patch, pretty please state this clearly
(instead of just not commenting it).

It's against dmd 1.053 (1.054/55 don't work for me because of other bugs).

--- a/mtype.c
+++ b/mtype.c
@@ -3888,7 +3888,7 @@ Expression *TypeEnum::dotExp(Scope *sc, Expression *e,
Identifier *ident)
        if (ident == Id::max ||
            ident == Id::min ||
            ident == Id::init ||
-           ident == Id::stringof ||
+           //ident == Id::stringof ||
            !sym->memtype
           )
        {

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 14, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2881


Vladimir <thecybershadow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow@gmail.com
            Version|1.041                       |1.005
           Severity|normal                      |major


--- Comment #2 from Vladimir <thecybershadow@gmail.com> 2010-03-14 05:04:34 PDT ---
Wow, what an ugly bug. This bug obliterates the entire concept of iterating over all the fields of a struct/class using .tupleof, if there's an enum field in it.

Also, I just checked and it's not a regression - this bug existed ever since .stringof appeared in DMD 1.005.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 14, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2881



--- Comment #3 from nfxjfg@gmail.com 2010-03-14 10:06:36 PDT ---
Vladimir, did the patch I posted fix the problem for you, without regressions in other parts of the code?

(Really nice that someone else cares about this problem. Maybe I can stop requiring a patched compiler for my code in a far, distant, feature?)

Just noting: bug 3651 is similar but unrelated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2881



--- Comment #4 from nfxjfg@gmail.com 2010-04-29 01:42:30 PDT ---
If you just want to get the member names of a struct, there's an easy work around: use SomeStructType.tupleof.stringof and parse the result. Some strange inconsistency makes dmd use the actual member name even if the member's type is an enum.

Sadly, this makes parsing the .stringof result even more hacky and non-trivial than without bug 2881.

(If you use SomeStructType.tupleof[idx].stringof, when idx is the index of a member of an enum type, bug 2881 will make dmd to return the type name instead of the member name.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 02, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2881


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2010-06-01 20:13:48 PDT ---
http://www.dsource.org/projects/dmd/changeset/512

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