Bug 8998 – 'inout pure' returns immutable, which in reality is mutable

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-11T15:25:00Z
Last change time
2013-03-03T16:55:24Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
acehreli

Comments

Comment #0 by acehreli — 2012-11-11T15:25:20Z
class A { int i; } class C { A a; this() { a = new A(); } // WRONG: Returns immutable(A) immutable(A) get() inout pure { return a; } } void main() { auto c = new C; immutable(A) imm_a = c.get(); assert(imm_a.i == 0); c.a.i = 100; // <-- changes immutable(A) assert(imm_a.i == 100); // <-- Oops! }
Comment #1 by yebblies — 2013-01-12T08:16:34Z
This looks similar to issue 9230. It it possible this case slipped through the cracks?
Comment #2 by k.hara.pg — 2013-01-20T08:34:18Z
https://github.com/D-Programming-Language/dmd/pull/1519 (In reply to comment #1) > This looks similar to issue 9230. It it possible this case slipped through the > cracks? No. Essentially, this is a regression which has been caused by fixing issue 7769. See the description in my pull request.
Comment #3 by github-bugzilla — 2013-03-03T16:07:29Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/49b4d94ce98437f408f6c84b9afc36f141c01d5a fix Issue 8998 - 'inout pure' returns immutable, which in reality is mutable By fixing issue 7769 (relax inout rule), we cannot assume a function with inout parameters as PUREstrong, because the return type may not have any inout indirections.