[Issue 4277] New: delegate reference wrong scope var value

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jun 5 07:27:34 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4277

           Summary: delegate reference wrong scope var value
           Product: D
           Version: 1.057
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: changlon at gmail.com


--- Comment #0 from changlon <changlon at gmail.com> 2010-06-05 07:27:33 PDT ---
-------------------------------------------------------------------------------
extern(C) void printf(char*, ... );

interface MyCall{
    void call(int);
}

class MyObject{
    MyCall[] list;

    void add(MyCall _mycall){
        list    ~= _mycall ;
    }

    void call(int i){
        foreach( c ; list) {
            c.call(i);
        }
    }
}


class MyTest {
    public void run(){
        MyObject obj    = new MyObject ;

        test3(obj);
        test2(obj);
        test1(obj);

        obj.call(3);
    }

    static void test1(char[] name = "test1\0" )(MyObject obj){
        printf("out: `%s` = `%x` \n\0".ptr ,  name.ptr, cast(void*) obj );
        obj.add( new class( delegate(int i){
            printf("in: `%s` = `%x` \n\0".ptr ,  name.ptr, cast(void*) obj );
        } ) MyCall{
            void delegate(int) dg;
            this(void delegate(int) _dg){
                this.dg    = _dg;
            }
            void call(int i) {
                dg(i);
            }
        } ) ;
    }

    void test2(MyObject obj){
        test1!("test2\0")(obj);
    }

    void test3(ref MyObject obj){
        test1!("test3\0")(obj);
    }
}

void main(){
    auto t    = new MyTest;
    t.run;
}
-------------------------------------------------------------------------------

out: `test3` = `a42fe0` 
out: `test2` = `a42fe0` 
out: `test1` = `a42fe0` 
in: `test3` = `414204` 
in: `test2` = `414204` 
in: `test1` = `12fe88`

-- 
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