code taken from bug 13343
struct S
{
int x;
}
alias T = immutable(S);
pragma(msg, typeof(__traits(getMember, T, "x")).stringof);
pragma(msg, typeof(T.x).stringof);
Output:
1>int
1>immutable(int)
Comment #1 by dlang-bot — 2020-05-30T13:28:16Z
@BorisCarvajal created dlang/dmd pull request #11200 "Fix Issue 20884 - Using getMember with a type as first argument can l…" fixing this issue:
- Fix Issue 20884 - Using getMember with a type as first argument can lose type qualifiers.
https://github.com/dlang/dmd/pull/11200
Comment #2 by dlang-bot — 2020-05-30T23:13:58Z
dlang/dmd pull request #11200 "Fix Issue 20884 - Using getMember with a type as first argument can l…" was merged into stable:
- aa33b64dfbe78a6621314472e1ad88ea5aa2afcb by Boris Carvajal:
Fix Issue 20884 - Using getMember with a type as first argument can lose type qualifiers.
https://github.com/dlang/dmd/pull/11200
Comment #3 by pro.mathias.lang — 2022-01-26T12:01:07Z
This wasn't fully fixed. Ran into this one today:
```
pragma(msg, __VERSION__);
template FieldRef (T, string name)
{
alias Ref = __traits(getMember, T, name);
alias Type1 = typeof(Ref);
alias Type2 = typeof(__traits(getMember, T, name));
pragma(msg, "Instantiating FieldRef: ", T, ".", name, " => ", Type1, " versus ", Type2);
}
struct Config
{
Inner inner;
}
struct Inner
{
char[] value;
}
alias IConfig = immutable(Config);
alias Result = FieldRef!(IConfig, `inner`);
alias ResultBis = FieldRef!(Result.Type2, "value");
```
Result:
```
2098L
Instantiating FieldRef: immutable(Config).inner => Inner versus immutable(Inner)
Instantiating FieldRef: immutable(Inner).value => char[] versus immutable(string)
```
As you can see, using the `__traits` directly works, but using an `alias` to the `__traits` still has the bug. This was tested with nightly (2.098), the aforementioned PR was released in v2.092.
Comment #4 by boris2.9 — 2022-01-27T00:13:53Z
That is an alias bug, replace the getMember trait with 'mixin("T." ~ name)' in your code and the result is the same.
```
alias Ref = mixin("T." ~ name);
...
alias Type2 = typeof(mixin("T." ~ name));
```
I think it's duplicated of issue 2704 (really old, probably there are more reports out there).
Some different but related bugs are issue 13343 and issue 20863.
There is a generic alias problem with respect to aggregate types (that have qualifiers) because the duality of them being a symbol and type at the same time, it also extends when interacting with their members.
This report was about fixing '__traits(getMember)' so maybe you should move the test case to 2704 and keep this closed.
Comment #5 by robert.schadek — 2024-12-13T19:08:57Z