Bug 20047 – call of static nested function ignores purity

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-07-13T16:22:10Z
Last change time
2019-07-15T13:14:57Z
Keywords
accepts-invalid, pull, safe
Assigned to
No Owner
Creator
ag0aep6g
See also
https://issues.dlang.org/show_bug.cgi?id=14039

Comments

Comment #0 by ag0aep6g — 2019-07-13T16:22:10Z
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.
Comment #1 by slavo5150 — 2019-07-13T23:56:29Z
This behavior was introduced in https://github.com/dlang/dmd/pull/4344 as a fix to Issue 14039
Comment #2 by dlang-bot — 2019-07-14T12:41:52Z
@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 20047 - call of static nested function ignores purity https://github.com/dlang/dmd/pull/10172
Comment #3 by dlang-bot — 2019-07-15T13:14:57Z
dlang/dmd pull request #10172 "fix handling of static impure functions nested in pure functions (issues 20047 and 20050)" was merged into master: - ccc7ed3d98f254b3326f0a7d06ebcb33f9038a1d by aG0aep6G: fix issue 20047 - call of static nested function ignores purity https://github.com/dlang/dmd/pull/10172