Bug 23073 – [dip1000] scope inference from pure doesn't consider self-assignment

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-04-30T21:50:20Z
Last change time
2022-08-17T19:50:30Z
Keywords
pull
Assigned to
No Owner
Creator
Dennis

Comments

Comment #0 by dkorpel — 2022-04-30T21:50:20Z
``` @safe: class C { C next; } void assignNext(C c) pure nothrow @nogc { c.next = c; } C escape() @nogc { scope C c = new C(); assignNext(c); return c.next; } void main() { C dangling = escape(); } ``` `assignNext` should not be callable on a `scope` parameter. The compiler sees no other parameters that c could be assigned to, but doesn't consider that mutable aggregates may have extra pointer layers, allowing you to escape a scope pointer because of the lack of transitive scope.
Comment #1 by dlang-bot — 2022-06-15T16:06:30Z
@dkorpel created dlang/dmd pull request #14217 "Fix 23073 - scope inference from pure doesn't consider self-assignment" fixing this issue: - Fix 23073 - scope inference from pure doesn't consider self-assignment https://github.com/dlang/dmd/pull/14217
Comment #2 by bugzilla — 2022-08-16T01:00:16Z
Note that if `pure` is removed from assignNext(), the error is correctly diagnosed and reported.
Comment #3 by bugzilla — 2022-08-16T01:01:59Z
I.e.: test3.d(17): Error: scope variable `c` assigned to non-scope parameter `c` calling `assignNext` (Although calling both variables `c` makes the error message a bit confusing.)
Comment #4 by dlang-bot — 2022-08-17T19:50:30Z
dlang/dmd pull request #14217 "Fix 23073 - scope inference from pure doesn't consider self-assignment" was merged into master: - e7e00ffa2461f309b1bca8c25cc5b7c5f7397f75 by Dennis Korpel: Fix 23073 - scope inference from pure doesn't consider self-assignment https://github.com/dlang/dmd/pull/14217