Bug 9461 – Ability to break typesystem with `inout`

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-06T04:17:00Z
Last change time
2013-02-17T21:52:30Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
verylonglogin.reg

Comments

Comment #0 by verylonglogin.reg — 2013-02-06T04:17:44Z
Implicit conversion from `inout(<derived class>)[]` to `inout(<base class>)[]` must not be allowed (just like for unqualified case) as `inout` can be `<no qualifier>` (i.e. mutable): --- class A { } class B: A { } inout(A)[] getBArrayAsAArray(inout(B)[] bArr) { return bArr; } void main() { B[] bArr = [new B()]; getBArrayAsAArray(bArr)[0] = new A(); // bArr[0] not a `B` any more... } ---
Comment #1 by k.hara.pg — 2013-02-06T19:57:28Z
Similar problem exists in: - AA key conversion - AA value conversioin - Pointer target conversion - static to dynamic array conversion But, bare class conversion inout(B) to inout(A) still be allowed. Test case: ---- class A {} class B : A {} void conv1(inout(B)[] x) { inout(A)[] y = x; } // should be NG void conv2(int[inout(B)] x) { int[inout(A)] y = x; } // should be NG void conv3(inout(B)[int] x) { inout(A)[int] y = x; } // should be NG void conv4(inout(B)* x) { inout(A)* y = x; } // should be NG void conv5(ref inout(B)[1] x) { inout(A)[] y = x; } // should be NG void conv6(inout(B) x) { inout(A) y = x; } // should be OK
Comment #2 by k.hara.pg — 2013-02-06T20:09:13Z
Comment #3 by github-bugzilla — 2013-02-17T21:49:43Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/3241c48f8bfd1e3bd0be0ee88a9b961baf42ff93 fix Issue 9461 - Ability to break typesystem with `inout` https://github.com/D-Programming-Language/dmd/commit/62e77c805ab01043c01da76f5a7ec3d67341399c Merge pull request #1633 from 9rnsr/fix9461 Issue 9461 - Ability to break typesystem with `inout`