[Issue 20047] New: call of static nested function ignores purity

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jul 13 16:22:10 UTC 2019


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: nobody at puremagic.com
          Reporter: ag0aep6g at gmail.com

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.

--


More information about the Digitalmars-d-bugs mailing list