[Issue 14781] New: impure delegate to pure function context should be able to modify context

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jul 7 08:56:10 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14781

          Issue ID: 14781
           Summary: impure delegate to pure function context should be
                    able to modify context
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: schveiguy at yahoo.com

In a followup to issue 9148, which made this illegal:

int impureFuncCall() { static int g; return g; }
auto foo(out int delegate() pure pureDg) pure {
    int x;
    auto bar()() {
        impureFuncCall();
            x = 1;  // Error: impure function 'bar' cannot access variable 'x'
        // declared in enclosing pure function 'foo'
    }

    pureDg = &(bar!());

    int dg() pure { return x;}
    return &dg;
}


This should be allowed. This doesn't violate purity of the returned delegate
because the context pointer is mutable -- it's weak pure.

This is similar to how a class can have pure and impure functions both
accessing the same data.

--


More information about the Digitalmars-d-bugs mailing list