www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22012] New: enum: dotExp lookups allow recursive dereference

https://issues.dlang.org/show_bug.cgi?id=22012

          Issue ID: 22012
           Summary: enum: dotExp lookups allow recursive dereference
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

This is valid because enum members are of their parent type.

So whilst, strange to look at, at least it is logical.
---
enum Theme { na, batman }
auto song = Theme.na.na.na.na.na.na.na.na.na.na.na.na.na.na.na.batman;
---

A slight variant on the theme is also valid, because when an ident isn't found,
the dotExp is passed on to the base type.
---
struct Batman { int batman; }
enum Theme { na = Batman(0) }
auto song = Theme.na.na.na.na.na.na.na.na.na.na.na.na.na.na.na.batman;
---

Where an issue with this happens though, is when an enum member shares the same
name as a base type member or property.
---
struct S { int hide; }
enum E : S { hide = S(42) }
pragma(msg, E);                     // E
pragma(msg, E.hide);                // S(42)
pragma(msg, E.hide);                // S(42)
pragma(msg, E.hide.hide);           // S(42)
pragma(msg, E.hide.hide.hide);      // S(42)
pragma(msg, E.hide.hide.hide.hide); // S(42)
pragma(msg, (cast(S)E.hide).hide);  // 42
---

Adding an issue for posterity. Though this seems like an amusing quirk to the
language, rather than a problem that requires fixing.

--
Jun 10