[Issue 5711] New: Accessing local variable of a function in which an inner class is instantiated trashes this.outer
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Mar 6 10:05:57 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5711
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
AssignedTo: nobody at puremagic.com
ReportedBy: smjg at iname.com
--- Comment #0 from Stewart Gordon <smjg at iname.com> 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 -----
4
3
4202691
----- DMD 2.052 -----
4
3
0
----------
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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list