www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - The .outer property

reply Iain Buclaw <ibuclaw ubuntu.com> writes:
Is this behaviour correct? Should it even be legal to blindly allow access to
members/fields via the .outer context pointer (that may not even be there as
shown in this instance)?

class Outer
{
    int w = 3;
    void method()
    {
        int x = 4;
        new class Object
        {
            this()
            {
                assert(w == 3);              // Passes
                //assert(x == 4);              // Passes
                assert(this.outer.w == 3);   // Fails if above is uncommented
            }
        };
    }
}

Regards
Mar 05 2011
next sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
On 05/03/2011 12:11, Iain Buclaw wrote:
 Is this behaviour correct? Should it even be legal to blindly allow access to
 members/fields via the .outer context pointer (that may not even be there as
 shown in this instance)?

 class Outer
 {
      int w = 3;
      void method()
      {
          int x = 4;
          new class Object
          {
              this()
              {
                  assert(w == 3);              // Passes
                  //assert(x == 4);              // Passes
                  assert(this.outer.w == 3);   // Fails if above is uncommented
<snip> There's clearly a bug at work here. It seems that there's a clash between two context pointers: this and the enclosing function. The compiler should either distinguish between the two or reject the code. I'll investigate. Stewart.
Mar 06 2011
prev sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
On 05/03/2011 12:11, Iain Buclaw wrote:
 Is this behaviour correct? Should it even be legal to blindly allow access to
 members/fields via the .outer context pointer (that may not even be there as
 shown in this instance)?
<snip> Bug filed: http://d.puremagic.com/issues/show_bug.cgi?id=5711 Stewart.
Mar 06 2011