Summary: Accessing local variable of a function in which an
                    inner class is instantiated trashes this.outer
           Product: D
           Version: D1 & D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: spec, wrong-code
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Stewart Gordon <> 2011-03-06 10:02:59 PST ---
Based on a newsgroup post by Iain Buclaw.

import std.stdio;

class Outer {
    int w = 3;
    void method() {
        int x = 4;
        new class Object {
            this() {
                writefln("%d", x);  // remove to suppress bug
                writefln("%d", w);
                writefln("%d", this.outer.w);

void main() {
    (new Outer).method();
----- DMD 1.067 -----
----- DMD 2.052 -----

It would appear that DMD is getting confused over whether the context pointer
of the inner class points to the stack frame of method or the Outer object. 
Which is it meant to be?

Moreover, is the use of x inside the constructor meant to be legal?  If the
context pointer points to the Outer, it shouldn't be legal in methods, though I
suppose it can still be allowed in the constructor.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to