Bug 23617 – traits(child) compile error need this for something that doesn't need this
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-01-10T20:15:01Z
Last change time
2023-01-12T22:06:56Z
Keywords
pull
Assigned to
No Owner
Creator
Adam D. Ruppe
Comments
Comment #0 by destructionator — 2023-01-10T20:15:01Z
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.
Comment #1 by dlang-bot — 2023-01-12T12:29:33Z
@RazvanN7 created dlang/dmd pull request #14807 "Fix Issue 23617 - traits(child) compile error need this for something that doesn't need this" fixing this issue:
- Fix Issue 23617 - traits(child) compile error need this for something that doesn't need this
https://github.com/dlang/dmd/pull/14807
Comment #2 by dlang-bot — 2023-01-12T22:06:56Z
dlang/dmd pull request #14807 "Fix Issue 23617 - traits(child) compile error need this for something that doesn't need this" was merged into master:
- 5028d8ea204cd57030eaceaf16bf5ae43ea130de by RazvanN7:
Fix Issue 23617 - traits(child) compile error need this for something that doesn't need this
https://github.com/dlang/dmd/pull/14807