www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15094] New: __traits(getMember) fails when the source is a


          Issue ID: 15094
           Summary: __traits(getMember) fails when the source is a
                    struct/class field
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: initrd.gz gmail.com

Attempting to use `__traits(getMember)` with a sub-struct/field fails with a
`need 'this'` error.

Example code:

    import std.stdio;

    struct Foo {
        int i;

    struct Bar {
        Foo foo;

    void main() {
        Bar bar;
        writeln(__traits(getMember, bar.foo, "i"));


    $ rdmd ~/test.d
    /home/col/test.d(14): Error: need 'this' for 'i' of type 'int'
    Failed: ["dmd", "-v", "-o-", "/home/col/test.d", "-I/home/col"]

It's possible, but annoying, to work around this by storing a local pointer to
the field first.

    auto foo = &bar.foo;
    writeln(__traits(getMember, foo, "i"));

Sep 21 2015