On Mon, 07 Nov 2011 05:49:52 -0500, bearophile <[email protected]> wrote:

Given how much often I find this problem in D coding, is someone willing and able to write a patch to allow code like this (it's in Bugzilla, with normal priority)?


const struct Foo {
    const int[5] a;
    const int[] b;
    const int[int] aa;
    this(in int n) pure {
        this.a[] = n; // line 6
        this.b = new int[5];
        this.b[0] = n; // line 8
        this.aa[1] = 2; // line 9
    }
}
void main() {}


The latest DMD gives:

test.d(6): Error: slice this.a[] is not mutable
test.d(8): Error: this.b[0] isn't mutable
test.d(9): Error: this.aa[1] isn't mutable

Of those, I think the only one which should be fixed is line 6.

Line 8 is invalid, because a const member is only allowed to be initialized *once* in a constructor.

Line 9 I think is not conceptually invalid, but you aren't *assigning* aa, you are using aa.

I would expect this to be valid:

this.aa = [1:2];

-Steve

Reply via email to