The code below has two unittests. The first one fails to compile and generates an error "this for foo needs to be type Foo not type Bar". A similar error would be given to do the same thing with an alias to the struct member. The second one has broadly the same functionality, but replaces the structs with classes and successfully compiles. Ideally there would be some kind of workaround for structs. For instance, alias x.foo this; fails to compile but would be a syntax consistent with other D features. unittest { static struct Foo { int value; int foo() { return value + 1; } } static struct Bar { Foo x; alias bar = x.foo; } Bar x = Bar(Foo(1)); assert(x.bar == 2); } unittest { static class Foo { int value; this(int x) { value = x;} int foo() { return value + 1; } } static class Bar : Foo { this(int x) { super(x);} alias bar = foo; } Bar x = new Bar(1); assert(x.bar == 2); }
This appears to be related to another known bug. *** This issue has been marked as a duplicate of issue 6842 ***