struct Memory { mixin Wrapper!(); } struct Image { Memory sup; alias sup this; } mixin template Wrapper() { } $ dmd -c test.d DMD v2.054 DEBUG test.d(8): Error: alias this there can be only one alias this As soon as the template precedes Image, it works. In my real code this is all spread among different modules, so it also is an order of compilation dependent issue.
Well, forget the last half sentence ;) btw, I probably would never have figured this out without DustMite :)
This is a bug related to forward reference. struct Memory { mixin Wrapper!(); } //mixin template Wrapper() {} // OK struct Image { Memory sup; alias sup this; } mixin template Wrapper() {} // NG
https://github.com/D-Programming-Language/dmd/pull/471 This patch does not solve forward reference order problem, and has an issue. struct S { int value; alias value this; alias value this; // alias this forwards to same symbol is allowed } But I think this is acceptable issue.
(In reply to comment #2) > This is a bug related to forward reference. > > struct Memory > { > mixin Wrapper!(); > } > //mixin template Wrapper() {} // OK > struct Image > { > Memory sup; > alias sup this; > } > mixin template Wrapper() {} // NG Well as I said, the code is spread over several modules. So it's hard to make sure Wrapper is processed first.
btw, now it tells Error: alias this test.Image.__anonymous there can be only one alias this
https://github.com/D-Programming-Language/dmd/commit/b63f4f4d3db0cf421ea7b266e232967fb20fb1c1