D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1979 - Anonymous class with confused context pointer
Summary: Anonymous class with confused context pointer
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-08 13:09 UTC by Frank Benoit
Modified: 2014-02-24 15:33 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Frank Benoit 2008-04-08 13:09:50 UTC
The following snippet shows an inner anonymous class, that uses the constructor to copy local values to member var. This is to make a closure behaviour.

When the inner class later tries to access the outer class, a segmentation fault happens.

The compiler should either given an error or it should work.

void main(){
    auto o = new Outer;
    o.run(5);
}

interface Intf {
    void doIt();
}

class Outer {
    int i;
    void inc( int v ){
        i += v ;
    }
    void run( int v2 ){
        auto i = new class Intf {
            int v2_;
            this(){
                v2_ = v2;
            }
            void doIt(){
                inc( v2_ ); // (1) segmentation fault
            }
        };
        i.doIt();
    }
}
Comment 1 Don 2009-04-18 03:43:02 UTC
This doesn't segfault for me in DMD1.042. Has it been fixed?
Comment 2 Don 2009-09-16 02:39:16 UTC
This was fixed in either 1.029 or 1.030. Works now.