www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20047] New: call of static nested function ignores purity

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

--
Jul 13 2019