digitalmars.D.bugs - [Issue 14781] New: impure delegate to pure function context should
- via Digitalmars-d-bugs (32/32) Jul 07 2015 https://issues.dlang.org/show_bug.cgi?id=14781
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 puremagic.com Reporter: schveiguy 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. --
Jul 07 2015