July 14, 2019 [Issue 20050] New: pure function should be able to return function pointer to impure static nested function | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20050 Issue ID: 20050 Summary: pure function should be able to return function pointer to impure static nested function Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: ag0aep6g@gmail.com 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. -- |
Copyright © 1999-2021 by the D Language Foundation