www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1759] New: Closures and With Statements


           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 digitalmars.com
        ReportedBy: xnknet 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

Jan 01 2008