www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - alias this and outer

Hello all,

Is there any reason why using,

     alias this.outer this;

should not be possible in nested classes?  Consider the following example:

//////////////////////////////////////////
import std.stdio;

class A
{
     class B
     {
         auto bar()  property
         {
             return this.outer.n;
         }
     }

     private int n;

     public B foo;

     this(int n)
     {
         this.n = n;
         this.foo = new B;
     }
}

void main()
{
     auto a = new A(22);

     writeln(a.foo.bar);
}
//////////////////////////////////////////

... which works fine; but if I replace the declaration of the nested class B
with,

     class B
     {
         alias this.outer this;
         auto bar()  property
         {
             return n;
         }
     }

then I get a compiler error:

aliasouter.d(7): Error: semicolon expected to close alias declaration
aliasouter.d(7): Error: found ';' when expecting '('
aliasouter.d(8): Error: function declaration without return type. (Note that 
constructors are always named 'this')
aliasouter.d(9): Error: found '{' when expecting ')'
aliasouter.d(10): Error: semicolon expected following function declaration
aliasouter.d(10): Error: Declaration expected, not 'return'
aliasouter.d(23): Error: unrecognized declaration

Is there an actual reason why "alias this.outer this;" should not be allowed
(in 
which case, surely the error message should be more explicit), or is this a bug?

Thanks and best wishes,

     -- Joe
Apr 13 2014