On Sunday, 22 March 2015 at 12:58:25 UTC, Stefan Koch wrote:
dmd infers function closures impure if impure functions are defined within them. even if those are never called and can never be accessed outside of the closure.

Example :

int a;
void closure() pure {
  impure_function() {
    a++;
   }
}
t.d(4): Error: pure function 't.closure.impure_function' cannot access mutable static data 'a'

is this intended ?

I think this was not intended and is simply a side effect of limited D call graph analysis. Relaxing that limitation makes sense to me because unused impure function can be used for compile-time reflection or returned from pure function as a result (you need to ensure it does not capture pure functions as closure context in that case)

Reply via email to