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