Hmm.. actually, it seems there have been plenty of reports of
this issue already. Didn't see it the first time:
http://d.puremagic.com/issues/show_bug.cgi?id=6174
On Friday, 13 July 2012 at 18:09:59 UTC, Era Scarecrow wrote:
I would think the best solution is to create a mutable local
version, and then assign the immutable global one when you are
done.
Thanks for the workaround. But I'm actually more interested in
whether or not this is a compiler
The following code doesn't compile. It seems like a compiler bug
to me, but I can't find a bug report about it. Is it a bug?
private immutable(int[]) constants;
shared static this()
{
constants.length = 10;
constants[0] = 123; // Error: constants[0] isn't mutable
}
On Friday, July 13, 2012 12:15:33 Tommi wrote:
The following code doesn't compile. It seems like a compiler bug
to me, but I can't find a bug report about it. Is it a bug?
private immutable(int[]) constants;
shared static this()
{
constants.length = 10;
constants[0] = 123; //
I guess it's because you have an array of constants (immutables).
The array is not immutable though. I could be wrong, I'm not an
expert or D syntax :)
When you use the length property it allocates space and assigns
it to the immutable array. the array now contains data (10 0's).
You've said you won't change any data in it's declaration but the
array itself can be changed (appending or a different array).
I would think the best solution is
On 07/13/2012 11:09 AM, Era Scarecrow wrote:
I would think the best solution is to create a mutable local version,
and then assign the immutable global one when you are done.
And there wouldn't be a copy with std.exception.assumeUnique:
import std.exception;
private immutable(int[])