www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13343] New: Strange behaviour aliasing struct members


          Issue ID: 13343
           Summary: Strange behaviour aliasing struct members
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: turkeyman gmail.com

Can anyone explain this to me:

struct S
  int x;

alias T = immutable(S);
enum member = "x";

import std.typetuple;
alias AliasMember(T, string member) = Alias!(__traits(getMember, T, member));
alias AliasMember2(T, string member) = Alias!(mixin("T."~member));

pragma(msg, typeof(AliasMember!(T, member)).stringof);
pragma(msg, typeof(AliasMember2!(T, member)).stringof);
pragma(msg, typeof(__traits(getMember, T, member)).stringof);
pragma(msg, typeof(mixin("T."~member)).stringof);


I don't understand... the 4th one get's it right, it is immutable(int).
The traits lookups seem to lose the immutable part from T. (is this a bug?)
But the real surprise here is the second one; the same mixin lookup piped
through an alias loses the immutable part too... that can't be right?

Something can't be right here... :/
I would have expected all four to be immutable(int)...?

Aug 20 2014