www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10951] New: EnumMembers returns duplicate members for enums

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

           Summary: EnumMembers returns duplicate members for enums
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Optlink
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-09-02
06:26:08 PDT ---
-----
import std.conv;
import std.stdio;
import std.string;
import std.traits;
import std.typetuple;
import std.socket;

void main()
{
    string[] enums = to!(string[])([EnumMembers!SocketOption]);
    writeln(enums.join("\n"));
}
-----

Prints:

DEBUG
BROADCAST
REUSEADDR
LINGER
OOBINLINE
SNDBUF
RCVBUF
DONTROUTE
SNDTIMEO
RCVTIMEO
ERROR
KEEPALIVE
ACCEPTCONN
RCVLOWAT
SNDLOWAT
TYPE
DEBUG  -- note duplicate!
REUSEADDR -- note duplicate!
IPV6_MULTICAST_IF
IPV6_MULTICAST_LOOP
IPV6_MULTICAST_HOPS
IPV6_JOIN_GROUP
IPV6_LEAVE_GROUP
IPV6_V6ONLY

The workaround for user code is to use NoDuplicate from std.typetuple:

string[] enums = to!(string[])([NoDuplicates!(EnumMembers!SocketOption)]);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 02 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10951


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com


--- Comment #1 from monarchdodra gmail.com 2013-09-02 07:13:01 PDT ---
The root issue appears to be that enums can have identifiers with duplicate
values:

//----
writefln("%(%d\n%)", [EnumMembers!SocketOption]);
//----
1
32
4
128
256
4097
4098
16
4101
4102
4103
8
2
4100
4099
4104
1 //HERE
4 //HERE
9
11
10
12
13
27
//----

So I'm not entirely sure EnumMembers is actually at fault here. It's the enum
to string conversion that is "breaking". But at the same time, there are too
enum members with the same value, so I'm not sure this is fixable. At best,
documented and worked around.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 02 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10951


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|Optlink                     |Phobos


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-09-02
07:24:49 PDT ---
(In reply to comment #1)
 So I'm not entirely sure EnumMembers is actually at fault here. It's the enum
 to string conversion that is "breaking". But at the same time, there are too
 enum members with the same value, so I'm not sure this is fixable. At best,
 documented and worked around.
Hmm yeah, you're right. I think I'll just make a pull with a doc fix, by refering to NoDuplicates if someone wants to do code-generation with this trait. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 02 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10951


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
         AssignedTo|nobody puremagic.com        |andrej.mitrovich gmail.com


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-09-02
07:32:49 PDT ---
https://github.com/D-Programming-Language/phobos/pull/1541

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 02 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10951


monarchdodra gmail.com changed:

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


--- Comment #4 from monarchdodra gmail.com 2013-09-03 03:44:04 PDT ---
I'm closing as "invalid", lest someone think, reading the title, that
EnumMembers now doesn't return dupes.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 03 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10951


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |FIXED
            Summary|EnumMembers returns         |EnumMembers should document
                   |duplicate members for enums |about returning duplicate
                   |                            |members


--- Comment #5 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-09-03
06:13:32 PDT ---
I've renamed the title and set it as fixed. Otherwise it won't be in the
changelog.

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