[Issue 18194] hasStaticMember doesn't work with static enum

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 5 21:08:46 UTC 2018


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

--- Comment #4 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
No, because an enum doesn't get associated with an instance. Like an alias,
it's just a scoped declaration. e.g.


struct S
{
    enum a = "foo";
    static enum b = "bar";
}

void main()
{
    auto c = S.a;
    auto d = S.b;
    auto e = S.init.a;
    auto f = S.init.b;
}

compiles just fine. And while it seems a bit bizarre, this compile just fine
too


struct S
{
    alias a = int;
    static alias b = int;
}

void main()
{
    alias c = S.a;
    alias d = S.b;
    alias e = S.init.a;
    alias f = S.init.b;
}


For that matter, the only influence that static has on variables over whether
you can use the type name or can use an an instance is that non-static
variables have to be referred to via the instance that they're associated with,
whereas static variables can be accessed either via the type name or via an
instance. Though in that case, it doesn't have anything do with static being
ignored like it does in the examples above.

All of this is why it was actually surprisingly difficult to come up with an
implementation of hasStaticMember which works in the general case. But
hasStaticMember can't distinguish between stuff that the compiler treats as the
same.

--


More information about the Digitalmars-d-bugs mailing list