[Issue 22012] New: enum: dotExp lookups allow recursive dereference
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 10 11:38:28 UTC 2021
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 at puremagic.com
Reporter: ibuclaw at 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.
--
More information about the Digitalmars-d-bugs
mailing list