https://issues.dlang.org/show_bug.cgi?id=20047
Issue ID: 20047
Summary: call of static nested function ignores purity
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: accepts-invalid, safe
Severity: normal
Priority: P1
Component: dmd
Assignee: [email protected]
Reporter: [email protected]
Came up here: https://github.com/dlang/druntime/pull/2673
This compiles but shouldn't:
----
int* m;
int* impure_function() { return m; }
int* pure_function() pure
{
static int* bug() { return impure_function(); }
return bug(); /* Shouldn't compile. `bug` isn't pure. */
}
void main()
{
m = new int(42);
immutable int* i = pure_function();
assert(*i == 42); /* passes */
*m = 13;
assert(*i == 42); /* fails; immutable value has changed */
}
----
Also affects @safe functions.
--