[Issue 14740] New: __traits(allMembers) returns erroneous 'this' member for types declared in functions.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Jun 27 00:25:52 PDT 2015


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

          Issue ID: 14740
           Summary: __traits(allMembers) returns erroneous 'this' member
                    for types declared in functions.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: Mihail.K at fimu.tk

__traits(allMembers) returns an additional non-existent member named 'this' for
types declared inside of functions.

-----

struct Foo
{
    this(int x, int y)
    {
    }
}

void main()
{
    struct Bar
    {
        this(int x, int y)
        {
        }
    }

    pragma(msg, __traits(allMembers, Foo)); // => __ctor
    pragma(msg, __traits(allMembers, Bar)); // => __ctor, this

    foreach(name; __traits(allMembers, Bar))
    {
        import std.stdio : writeln;
        typeof(__traits(getMember, Bar, name)).stringof.writeln;
    }
}

-----

$ dmd -run demo.d
> tuple("__ctor")
> tuple("__ctor", "this")
> demo.d(24): Error: no property 'this' for type 'Bar'

Note the extra member produced by __traits(allMembers, Bar), eventually leading
to a compilation error when referred to by __traits(getMember).

This is likely an oversight or error and should be removed as it serves no
purpose, and can cause problems when iterating over members of a type.

--


More information about the Digitalmars-d-bugs mailing list