digitalmars.D - It is a bug ?
- Du Liang (25/25) May 06 2009 import std.stdio;
- Jarrett Billingsley (4/5) May 06 2009 Declaring the variable like this uses a single array for all instances
- Denis Koroskin (2/7) May 06 2009 I believe this is a horrible inconsistency. It shouldn't be allowed in f...
- Georg Wrede (2/12) May 06 2009 Issue 2947 Submitted
- Georg Wrede (4/14) May 06 2009 writeln(typeof([2,2,2]).stringof);
- grauzone (28/38) May 06 2009 DWIM would be to let the compiler automatically move these instructions
import std.stdio;
class AB{
int A;
int B = 2;
int[] arrA;
int[] arrB = [2,2,2]; // arrB is static in[] or bug ?
this(){
this.A = 1;
this.arrA=[1,1,1];
}
}
void main(){
AB ab1 = new AB();
AB ab2 = new AB();
writeln(ab1.A, " | " ,ab1.B, " | " ,ab1.arrA, " | " ,ab1.arrB);
writeln(ab2.A, " | " ,ab2.B, " | " ,ab2.arrA, " | " ,ab2.arrB);
writeln("change...");
ab1.A = 10;
ab1.B = 20;
ab1.arrA[0] = 10;
ab1.arrB[0] = 20; // ab2.arrB = 20 why? bug?
writeln(ab1.A, " | " ,ab1.B, " | " ,ab1.arrA, " | " ,ab1.arrB);
writeln(ab2.A, " | " ,ab2.B, " | " ,ab2.arrA, " | " ,ab2.arrB);
readln();
}
May 06 2009
On Wed, May 6, 2009 at 10:06 AM, Du Liang <duliang.21 163.com> wrote:=A0 =A0 =A0 =A0int[] arrB =3D [2,2,2]; // arrB is static in[] =A0or 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 =3D arrB.dup;" in this().
May 06 2009
On Wed, 06 May 2009 19:33:03 +0400, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote:On Wed, May 6, 2009 at 10:06 AM, Du Liang <duliang.21 163.com> wrote: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.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().
May 06 2009
Denis Koroskin wrote:On Wed, 06 May 2009 19:33:03 +0400, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote:Issue 2947 SubmittedOn Wed, May 6, 2009 at 10:06 AM, Du Liang <duliang.21 163.com> wrote: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.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().
May 06 2009
Denis Koroskin wrote:On Wed, 06 May 2009 19:33:03 +0400, Jarrett Billingsley wrote:writeln(typeof([2,2,2]).stringof); int[3u] A literal string seems not to be immutable.On Wed, May 6, 2009 at 10:06 AM, Du Liang wrote: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.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().
May 06 2009
Denis Koroskin wrote:On Wed, 06 May 2009 19:33:03 +0400, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote: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(); } }On Wed, May 6, 2009 at 10:06 AM, Du Liang <duliang.21 163.com> wrote: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.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().
May 06 2009
grauzone Wrote:Denis Koroskin wrote:Thanks!On Wed, 06 May 2009 19:33:03 +0400, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote: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(); } }On Wed, May 6, 2009 at 10:06 AM, Du Liang <duliang.21 163.com> wrote: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.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().
May 06 2009
Du Liang wrote:grauzone Wrote:Um... Maybe I should clarify: it does NOT work like that right now! My post was more like a feature request.Denis Koroskin wrote:Thanks!On Wed, 06 May 2009 19:33:03 +0400, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote: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(); } }On Wed, May 6, 2009 at 10:06 AM, Du Liang <duliang.21 163.com> wrote: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.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().
May 07 2009









Georg Wrede <georg.wrede iki.fi> 