[Issue 1759] New: Closures and With Statements

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 1 08:48:24 PST 2008


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

           Summary: Closures and With Statements
           Product: D
           Version: 2.009
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: xnknet at gmail.com


The following code doesn't crash. However, it does print an unexpected value.
It should print 90, but instead it prints 4202678.

The bug can be worked around by referencing 'obj' directly.

struct SS{ int a, b, c; }
int delegate() addss(SS obj){
        with(obj) return {
                return a+b+c;
        };
}

void main(){
        SS obj = {15, 30, 45};
        auto l = addss(obj);
        writeln(l()); // Prints unexpected value
}


-- 



More information about the Digitalmars-d-bugs mailing list