www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17110] New: Proxy (and therefore Typedef) doesn't work for

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

          Issue ID: 17110
           Summary: Proxy (and therefore Typedef) doesn't work for type
                    alias members
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: john.loughran.colvin gmail.com

We get away with it for enums with CTFE of opDispatch but it's no good for
types etc.

Here's a reasonably large unittest, now someone just needs to fix the
implementation so it passes:

version(unittest)
{
    private int __global_n;
}

unittest
{
    import std.typecons : Typedef;
    import std.meta : AliasSeq;

    int n;

    struct S
    {
        alias X = int;
        alias Y() = int;
        alias Z(Q) = Q;
        alias A = AliasSeq!(n, float);
        alias B() = AliasSeq!(n, float);
        alias C(e...) = AliasSeq!(e, float);
        alias AS(Args ...) = AliasSeq!Args;
    }

    //alias TS = S; //for testing the tests without Typedef
    alias TS = Typedef!S;

    TS.X x;
    static assert(is(typeof(x) == int));
    TS.Y!() y;
    static assert(is(typeof(y) == int));
    TS.Z!int z;
    static assert(is(typeof(z) == int));

    alias a = TS.A;
    a[0] = 3;
    assert(n == 3);
    static assert(is(a[1] == float));
    alias b = TS.B!();
    b[0] = 4;
    assert(n == 4);
    static assert(is(b[1] == float));
    alias c = TS.C!__global_n;
    assert(__global_n == 4);
    static assert(is(c[1] == float));

    alias AS = TS.AS;
    alias L = AS!(__global_n, int, 4);
    alias R = AliasSeq!(__global_n, int, 4);
    assert(L[0] is R[0]);
    assert(is(L[1] == R[1]));
    assert(L[2] == R[2]);
}

--
Jan 20