Copying to an immutable array in a costructor

Jonathan M Davis jmdavisProg at gmx.com
Thu Oct 24 00:58:26 PDT 2013


On Thursday, October 24, 2013 09:02:24 bearophile wrote:
> This shows a limitation of the D type system:
> 
> 
> import std.algorithm: copy;
> immutable int[2] data;
> static this() {
>      foreach (i, x; [10, 20]) data[i] = x; // OK
>      data[] = [10, 20]; // OK
>      [10, 20].copy(data[]); // Error.
> }
> void main() {}

It's a compiler bug. immutable data should not be initialized more than once.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list