[Issue 20884] Using getMember with a type as first argument can lose type qualifiers.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 26 12:01:07 UTC 2022


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

Mathias LANG <pro.mathias.lang at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |pro.mathias.lang at gmail.com
         Resolution|FIXED                       |---

--- Comment #3 from Mathias LANG <pro.mathias.lang at gmail.com> ---
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.

--


More information about the Digitalmars-d-bugs mailing list