Bug 20050 – pure function should be able to return function pointer to impure static nested function
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-07-14T11:26:42Z
Last change time
2019-07-15T13:14:58Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
ag0aep6g
Comments
Comment #0 by ag0aep6g — 2019-07-14T11:26:42Z
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.
Comment #1 by dlang-bot — 2019-07-14T12:41:53Z
@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
Comment #2 by dlang-bot — 2019-07-15T13:14:58Z
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