March 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7766

           Summary: (Full Closures) Chain of nested functions fails
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: xinok@live.com


--- Comment #0 from Xinok <xinok@live.com> 2012-03-24 19:43:02 PDT ---
In the following code, you'd expect it to print 365. However, it prints a random number instead. The issue is that 'value' is referred to by 'foo', which is referred to by 'foo2'. DMD fails to detect this chain, so 'value' is allocated on the stack, not the heap. Once the function 'clbug' returns, 'value' is popped from the stack and so it ends up printing a random number.

value -> foo -> foo2

void main(){
    clbug()();
}

int delegate() clbug(){
    int value = 365;
    int foo(){
        writeln(value);
        return value;
    }
    int foo2(){
        return foo();
    }
    return &foo2;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7766


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug@yahoo.com.au
         Resolution|                            |DUPLICATE


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2012-03-27 23:23:02 PDT ---
Duplicate of bug 1841 - it's incorrect closure detection in nested functions.

*** This issue has been marked as a duplicate of issue 1841 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------