[Issue 11412] New: Allow nested pure functions to access outer function variables

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 1 09:57:40 PDT 2013


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

           Summary: Allow nested pure functions to access outer function
                    variables
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: verylonglogin.reg at gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2013-11-01 19:57:39 MSK ---
As an outer function is a context for its nested function it should be
accessible for weakly pure functions just like type instance for member
functions:
---
struct S
{
    int i;
    void f() pure
    {
        int j;
        void g() pure
        {
            ++i; // ok
            ++j; // currently error, looks inconsistent
        }
    }
}
---

Also this will allow things like this (usable e.g. for std.conv):
---
struct S
{
    void toString(scope void delegate(const(char)[]) pure) pure;
}

string sToStr(S s) pure
{
    string res;
    s.toString((chars) { res ~= chars; });
    return res;
}
---

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