---
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.