[Issue 4556] New: Misbehaving nested function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Aug 1 14:13:03 PDT 2010


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

           Summary: Misbehaving nested function
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2010-08-01 14:12:59 PDT ---
This is the 4th example from the title "Nested Classes" on the page
http://www.digitalmars.com/d/2.0/class.html :

import std.stdio;

class Base
{
    int foo() { return 1; }
}

Base func()
{   
    int m = 3;

    class Nested : Base
    {
    int foo() { return m; }
    }

    Base b = new Nested;

    assert(b.foo() == 3);    // Ok, func() is still active
    return b;
}

int test()
{
    Base b = func();
    return b.foo();        // Error, func().m is undefined
}

void main()
{
    writeln(test());  // writes 3, there was no error
}


According to the docs, this should not compile. 
This looks to me like some kind of automatic closure where foo() becomes a
delegate? I'm not sure..

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