Found while looking into issue 20047. Should compile: ---- int g = 0; void impure_function_1() { ++g; } void function() get_impure_function() pure { static void impure_function_2() { ++g; /* Error: pure function test.get_impure_function cannot access mutable static data g */ impure_function_1(); /* Error: pure function test.get_impure_function cannot call impure function test.impure_function_1 */ } return &impure_function_2; } void main() { auto f = get_impure_function(); f(); assert(g == 2); } ---- Just because `get_impure_function` is pure doesn't mean that `impure_function_2` also has to be pure.
@aG0aep6G created dlang/dmd pull request #10172 "fix handling of static impure functions nested in pure functions (issues 20047 and 20050)" fixing this issue: - fix issue 20050 - pure function should be able to return function pointer to impure static nested function https://github.com/dlang/dmd/pull/10172
dlang/dmd pull request #10172 "fix handling of static impure functions nested in pure functions (issues 20047 and 20050)" was merged into master: - e50097d7ca361a1d6ee5841459781aaf26f77466 by aG0aep6G: fix issue 20050 - pure function should be able to return function pointer to impure static nested function https://github.com/dlang/dmd/pull/10172