[Issue 11130] New: Regression (2.064 git-head): Enum members hijack module-scoped symbols in initializers

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 27 06:34:42 PDT 2013


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

           Summary: Regression (2.064 git-head): Enum members hijack
                    module-scoped symbols in initializers
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-09-27 06:34:40 PDT ---
This may or may not have been an intended change:

-----
enum A = 1;

enum E
{
    A = A
}

void main()
{
}
-----

$ dmd test.d
test.d(7): Error: enum member test.E.A circular reference to enum member

The workaround is simple for module-scoped enums, use the [dot] expression to
look up module-scoped symbols:

-----
enum A = 1;

enum E
{
    A = .A  // works
}

void main()
{
}
-----

However the following code does not have an easy workaround:

-----
void main()
{
    enum A = 1;

    enum E
    {
        // circular reference, cannot use ".A" here
        // because "A" is not in module scope
        A = A  
    }
}
-----

Above you would likely have to introduce an alias such as:

-----
void main()
{
    enum A = 1;
    alias thisA = A;
    enum E
    {
        A = thisA  // ok
    }
}
-----

If this regression was intended we're going to have to properly document it,
both in the docs and in the upcoming changelog.

The regression was found in DGui, where some enum members have the same name as
WinAPI constants, but were purposefully wrapped in the enum to make the
constants typed:

enum EdgeType : uint
{
    RAISED_OUTER = BDR_RAISEDOUTER,
    RAISED_INNER = BDR_RAISEDINNER,

    SUNKEN_OUTER = BDR_SUNKENOUTER,
    SUNKEN_INNER = BDR_SUNKENINNER,

    BUMP        = EDGE_BUMP,
    ETCHED      = EDGE_ETCHED,
    EDGE_RAISED = EDGE_RAISED,  // issue here
    SUNKEN      = EDGE_SUNKEN,
}

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


More information about the Digitalmars-d-bugs mailing list