It is a bug ?
grauzone
none at example.net
Wed May 6 11:19:09 PDT 2009
Denis Koroskin wrote:
> On Wed, 06 May 2009 19:33:03 +0400, Jarrett Billingsley <jarrett.billingsley at gmail.com> wrote:
>
>> On Wed, May 6, 2009 at 10:06 AM, Du Liang <duliang.21 at 163.com> wrote:
>>
>>> int[] arrB = [2,2,2]; // arrB is static in[] or bug ?
>> Declaring the variable like this uses a single array for all instances
>> of AB. You should initialize it in this() instead, or put "arrB =
>> arrB.dup;" in this().
>
> I believe this is a horrible inconsistency. It shouldn't be allowed in first place, because typeof([2,2,2]) is immutable(int)[] in this context.
DWIM would be to let the compiler automatically move these instructions
into all ctors.
class A {
int[] arrB = [2,2,2];
X x = new X();
this() {
code1();
}
this(int) {
code2();
}
}
would be transformed into
class A {
int[] arrB;
X x;
this() {
arrB = [2,2,2];
x = new X();
code1();
}
this(int) {
arrB = [2,2,2];
x = new X();
code2();
}
}
More information about the Digitalmars-d
mailing list