www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23617] New: traits(child) compile error need this for

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

          Issue ID: 23617
           Summary: traits(child) compile error need this for something
                    that doesn't need this
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P3
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: destructionator gmail.com

This code WORKS:

```
struct S {
        void foo() {}
}

struct Wrapper {
  size_t currentIndex;
  S[] arrayOfS;
  auto opDispatch(string name, T ...)(T t) {
    assert(currentIndex < arrayOfS.length);
    alias member = __traits(getMember, S, name);
    return __traits(child, arrayOfS[this.currentIndex], member)(t);
  }
}


void main() {
        Wrapper w;
        w.opDispatch!"foo"();
}
```

But change the alias to inline:

```
struct S {
        void foo() {}
}

struct Wrapper {
  size_t currentIndex;
  S[] arrayOfS;
  auto opDispatch(string name, T ...)(T t) {
    assert(currentIndex < arrayOfS.length);
    // no more separate alias
    return __traits(child, arrayOfS[this.currentIndex], __traits(getMember, S,
name))(t);
  }
}

void main() {
        Wrapper w;
        w.opDispatch!"foo"();
}
```

And get:

wtflol.d(10): Error: symbol expected as second argument of __traits `child`
instead of `this.foo`
wtflol.d(16): Error: template instance `wtflol.Wrapper.opDispatch!"foo"` error
instantiating



OR, change the `this.currentIndex` to just `currentIndex` in either example and
get:

wtflol.d(10): Error: need `this` for `currentIndex` of type `ulong`


So both arguments are attaching things incorrectly.

--
Jan 10 2023