Bug 13640 – [REG2.066] can break immutability with inout

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-10-19T20:51:00Z
Last change time
2015-02-21T09:11:12Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
ag0aep6g
Depends on
13621

Comments

Comment #0 by ag0aep6g — 2014-10-19T20:51:34Z
struct Array() { int* p; static struct Range { int* p; inout this(inout ref int* p) {this.p = p;} } /* Return type is not inout; shouldn't compile: */ Range r() inout { return inout(Range)(p); } } void main() { immutable int x = 42; auto a = immutable(Array!())(&x); auto r = a.r(); pragma(msg, typeof(r.p)); /* "int*" -- mutable, woops */ *r.p = 13; /* Shouldn't compile. */ assert(&x == r.p); /* Passes as it's supposed to. */ assert(x == 42); /* Passes, wat. */ assert(*r.p == 13); /* Passes, wat. */ assert(x == *r.p); /* Finally an assert that fails. */ }
Comment #1 by k.hara.pg — 2014-10-22T12:45:19Z
It's a regression from 2.066, introduced by implementing DIP29. https://github.com/D-Programming-Language/dmd/pull/3352
Comment #2 by github-bugzilla — 2014-10-30T05:32:41Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/7cf3baf8f0c75a7e3641786af4dfe0441e3918d6 fix Issue 13640 - can break immutability with inout https://github.com/D-Programming-Language/dmd/commit/c7edfb41f1e0c6ab10ae8a11905bb510dbb208d3 Merge pull request #4083 from 9rnsr/fix13640 [REG2.066] Issue 13640 - can break immutability with inout
Comment #3 by github-bugzilla — 2015-02-11T23:23:39Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/283aa4add2868dc7424c5232f18bbcfc392ed26a Use constConv in CallExp::implicitConvTo() and NewExp::implicitConvTo() As same as the fix for issue 13640 (commit: 7cf3baf8f0c75a7e3641786af4dfe0441e3918d6).
Comment #4 by github-bugzilla — 2015-02-18T03:38:40Z
Comment #5 by github-bugzilla — 2015-02-21T09:11:12Z