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! }
This looks similar to issue 9230. It it possible this case slipped through the cracks?
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.
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.