https://issues.dlang.org/show_bug.cgi?id=9148
--- Comment #18 from [email protected] --- (In reply to Kenji Hara from comment #17) > (In reply to timon.gehr from comment #16) > > I think this is not right. Why should impure nested functions not be able to > > access the enclosing context corresponding to frames of pure functions? > > Because the nested impure function may modify the context of other pure > functions. > > int g; > int impureFuncCall() { return g; } > > auto func(out int delegate() pure pureDg, out void delegate() impureDg) pure > { > int x = 1; // become a closure variable > > int foo() pure // weak purity > { > return x; > } > > auto bar()() > { > // modify the context of pure funciton 'foo' > // depending on the global state, > if (impureFuncCall()) > x = 2; // !! > } > > pureDg = &foo; > impureDg = &bar!(); > } > > void main() > { > int delegate() pure pureDg; > void delegate() impureDg; > > func(pureDg, impureDg); > > assert(pureDg() == 1); > > g = 1; // modify the global state > impureDg(); // modify the context of pureDg. > > assert(pureDg() == 1); // fails~ > } I understand. My question was why you consider this to be a _problem_. pureDg is weakly pure. I can change the context of a weakly pure delegate depending on global state in other ways if I want to. --
