On Sunday, 30 April 2017 at 23:35:43 UTC, Jonathan Marler wrote:
Any reason why "alias this" doesn't work at the module level? If I recall correctly, a module is really just a "class" under the hood, but when I tried to use it I got:

Error: alias this can only be a member of aggregate, not module <module-name>

It sort of does... almost.

module test3;

void testfun1()
{
}

void testfun2()
{
}

------------------------------------------

module test2;

class Test
{
    public import test3;
}

------------------------------------------

module test1;

import test2;

void main()
{
    Test.test3.testfun1(); //Ok
    Test.test3.testfun2(); //Ok

    import std.stdio;
    import test3;

    assert(&Test.test3.testfun1 == &testfun1); //Passes

    //What?
Test.testfun1(); Error: no property 'testfun1' for type 'test2.Test', did you mean 'testfun1'?
}

If you add this alias to Test then it will work as expected:

alias testfun1 = test3.testfun1;

Reply via email to