www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9930] New: Disallow accessing enum members through enum instance

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

           Summary: Disallow accessing enum members through enum instance
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-04-14
08:28:02 PDT ---
enum E
{
    A,
    B
}

void main()
{
    E e;

    if (e.A)  // should have been "if e == E.A"
    {
    }
}

This compiles, and it was a bug in my code. I don't see the benefit of being
able to access enum member through the instance instead of through the type. So
I think the above should become an error.

Of course "if (E.A)" through the type is and will be allowed to compile, but
the above might just catch a bug or two in user-code (it certainly wasted my
time tracking down the bug).

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-04-16
11:04:12 PDT ---
Note that this actually hides instance members:

struct S
{
    int a;  // hidden by member "a" in enum E
    bool opCmp(S s) { return 1; }
}

enum E : S
{
    a = S(1),
    b = S(2)
}

void main()
{
    E evar = E.a;
    assert(evar.a == 1);  // Error: evar.a is E here
}

I'm changing the report to a bug.

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



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-06-03
10:03:19 PDT ---
To make sure Issue 10253 is implementable, I'd still like the following to work
(which currently does):

-----
enum E
{
    A,
    B
}

struct S
{
    E e;
    alias e this;
}

auto x = S.A;  // equivalent to S.e.A, or E.A
-----

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