Bug 5284 – Array ops punch through const system

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-11-28T09:00:00Z
Last change time
2011-06-25T11:53:21Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
dfj1esp02
Blocks
2573

Comments

Comment #0 by dfj1esp02 — 2010-11-28T09:00:08Z
--- class A { int m=5; } int main() { A[] a=new A[1]; immutable(A)[] b=[new immutable(A)]; assert(b[0].m==5); a[]=b[]; //should not pass typecheck a[0].m=10; assert(b[0].m==5,"fail"); //line 18 return 0; } --- >dmd -w -debug -run test.d --- [email protected](18): fail
Comment #1 by dfj1esp02 — 2010-11-28T09:13:10Z
Interesting... --- class A { int m=5; } int main() { A[] a=new A[1]; int[] b=[0]; a[]=b[]; return 0; } --- this code gives error: cannot implicitly convert expression (b[]) of type int[] to const(A[]). Seems like the compiler tries to cast right-hand expression to const(typeof(left-hand expression)), then proceeds with copying.
Comment #2 by bugzilla — 2011-06-25T11:53:21Z