www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Static array .init function does not work

reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
import std.stdio;

void main()
{
 static int[2] a;
 a[0]=5;
 a[1]=10;
 a.init;
 writefln(a[0],",",a[1]);
}

Prints 5,10.  Remove "static" and it prints 0,0 as expected.

Also happens with class static arrays. 
Feb 24 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Thu, 24 Feb 2005 22:56:53 -0500, Jarrett Billingsley wrote:

 import std.stdio;
 
 void main()
 {
  static int[2] a;
  a[0]=5;
  a[1]=10;
  a.init;
  writefln(a[0],",",a[1]);
 }
 
 Prints 5,10.  Remove "static" and it prints 0,0 as expected.
 
 Also happens with class static arrays.
Confirmed. Here is another example ... <code> import std.stdio; void main() { static int a; int b; a=5; b=5; writefln("before a=%d b=%d", a, b); a.init; b.init; writefln(" after a=%d b=%d", a, b); } </code> -- Derek Melbourne, Australia 25/02/2005 3:10:14 PM
Feb 24 2005
parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
"Derek Parnell" <derek psych.ward> wrote in message 
news:16xo8j2vhhc9z$.1ub0088au56os$.dlg 40tude.net...
 On Thu, 24 Feb 2005 22:56:53 -0500, Jarrett Billingsley wrote:

 import std.stdio;

 void main()
 {
  static int[2] a;
  a[0]=5;
  a[1]=10;
  a.init;
  writefln(a[0],",",a[1]);
 }

 Prints 5,10.  Remove "static" and it prints 0,0 as expected.

 Also happens with class static arrays.
Confirmed. Here is another example ... <code> import std.stdio; void main() { static int a; int b; a=5; b=5; writefln("before a=%d b=%d", a, b); a.init; b.init; writefln(" after a=%d b=%d", a, b); } </code> -- Derek Melbourne, Australia 25/02/2005 3:10:14 PM
interesting. I didn't know b.init would change b. I thought it would just evaluate to b's initializer. To quote the spec: .init produces a constant expression that is the default initializer. If applied to a type, it is the default initializer for that type. If applied to a variable or field, it is the default initializer for that variable or field. Walter, can you make the doc more clear that b.init will change b? I assume the way to get the initializer for b without changing b is to do typeof(b).init? I'm not sure how this works with fields, though, since the initializer for the field depends on exactly which field you are talking about and not just the type of the field.
Feb 24 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Ben Hinkle wrote:
 "Derek Parnell" <derek psych.ward> wrote in message 
 news:16xo8j2vhhc9z$.1ub0088au56os$.dlg 40tude.net...
 
On Thu, 24 Feb 2005 22:56:53 -0500, Jarrett Billingsley wrote:


import std.stdio;

void main()
{
 static int[2] a;
 a[0]=5;
 a[1]=10;
 a.init;
 writefln(a[0],",",a[1]);
}

Prints 5,10.  Remove "static" and it prints 0,0 as expected.
Why expected? .init is a property which, AIUI, isn't supposed to have any side effect. <snip>
 interesting. I didn't know b.init would change b. I thought it would just 
 evaluate to b's initializer. To quote the spec:
 .init produces a constant expression that is the default initializer. If 
 applied to a type, it is the default initializer for that type. If applied 
 to a variable or field, it is the default initializer for that variable or 
 field.
 
 Walter, can you make the doc more clear that b.init will change b?
Only if that's the intended behaviour, which it most certainly isn't. Having .init do two completely different things depending on what it's applied to is no good for anyone, and I doubt this is among the kinds of warts that Walter would put into the language.
 I assume the way to get the initializer for b without changing b is to do 
 typeof(b).init?
No. The initialiser of a variable and the initialiser of a type are two different concepts. Suppose you have static int[2] a = [ 13, 42 ]; a[0] = 69; writefln(a[0],",",a[1]); writefln(a.init[0],",",a.init[1]); writefln(typeof(a).init[0],",",typeof(a).init[1]); writefln(a[0],",",a[1]); then the output should be 69,42 13,42 0,0 69,42 whereas with what you're making out it would be 69,42 13,42 13,42 13,42
 I'm not sure how this works with fields, though, since the 
 initializer for the field depends on exactly which field you are talking 
 about and not just the type of the field.
struct Qwert { int yuiop = 105; } void main() { Qwert asdfg = { yuiop: 23 }; writefln(Qwert.yuiop.init); writefln(asdfg.yuiop.init); } should output 105 23 Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Feb 25 2005
next sibling parent "Ben Hinkle" <bhinkle mathworks.com> writes:
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message 
news:cvmu8n$der$1 digitaldaemon.com...
 Ben Hinkle wrote:
 "Derek Parnell" <derek psych.ward> wrote in message 
 news:16xo8j2vhhc9z$.1ub0088au56os$.dlg 40tude.net...

On Thu, 24 Feb 2005 22:56:53 -0500, Jarrett Billingsley wrote:


import std.stdio;

void main()
{
 static int[2] a;
 a[0]=5;
 a[1]=10;
 a.init;
 writefln(a[0],",",a[1]);
}

Prints 5,10.  Remove "static" and it prints 0,0 as expected.
Why expected? .init is a property which, AIUI, isn't supposed to have any side effect. <snip>
 interesting. I didn't know b.init would change b. I thought it would just 
 evaluate to b's initializer. To quote the spec:
 .init produces a constant expression that is the default initializer. If 
 applied to a type, it is the default initializer for that type. If 
 applied to a variable or field, it is the default initializer for that 
 variable or field.

 Walter, can you make the doc more clear that b.init will change b?
Only if that's the intended behaviour, which it most certainly isn't. Having .init do two completely different things depending on what it's applied to is no good for anyone, and I doubt this is among the kinds of warts that Walter would put into the language.
agreed. I'd prefer the spec behavior over the current compiler behavior if given the choice.
Feb 25 2005
prev sibling next sibling parent kris <fu bar.org> writes:
Stewart Gordon wrote:
 Having .init do two completely different things depending on what it's 
 applied to is no good for anyone
Well said. This needs to be fixed.
Feb 26 2005
prev sibling parent reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stewart Gordon schrieb am Fri, 25 Feb 2005 10:22:15 +0000:
 Ben Hinkle wrote:
 "Derek Parnell" <derek psych.ward> wrote in message 
 news:16xo8j2vhhc9z$.1ub0088au56os$.dlg 40tude.net...
 
On Thu, 24 Feb 2005 22:56:53 -0500, Jarrett Billingsley wrote:


import std.stdio;

void main()
{
 static int[2] a;
 a[0]=5;
 a[1]=10;
 a.init;
 writefln(a[0],",",a[1]);
}

Prints 5,10.  Remove "static" and it prints 0,0 as expected.
Why expected? .init is a property which, AIUI, isn't supposed to have any side effect. <snip>
 interesting. I didn't know b.init would change b. I thought it would just 
 evaluate to b's initializer. To quote the spec:
 .init produces a constant expression that is the default initializer. If 
 applied to a type, it is the default initializer for that type. If applied 
 to a variable or field, it is the default initializer for that variable or 
 field.
 
 Walter, can you make the doc more clear that b.init will change b?
Only if that's the intended behaviour, which it most certainly isn't. Having .init do two completely different things depending on what it's applied to is no good for anyone, and I doubt this is among the kinds of warts that Walter would put into the language.
Added to DStress as http://dstress.kuehne.cn/run/init_01.d http://dstress.kuehne.cn/run/init_02.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCOojn3w+/yD4P9tIRApGIAJ9uz8sSCeE0VjMvHQNy8ceAvu2OSwCfZGHx nUgCo48l2KQEfV2p4BZKouo= =rv4+ -----END PGP SIGNATURE-----
Mar 17 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Thomas Kuehne wrote:
<snip>
 Added to DStress as
 http://dstress.kuehne.cn/run/init_01.d
 http://dstress.kuehne.cn/run/init_02.d
This line looks a little odd to me: assert(array.init==int.init); Aren't these incompatible types (int[2] and int)? Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Mar 18 2005
parent reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stewart Gordon schrieb am Fri, 18 Mar 2005 11:01:43 +0000:
 Thomas Kuehne wrote:
<snip>
 Added to DStress as
 http://dstress.kuehne.cn/run/init_01.d
 http://dstress.kuehne.cn/run/init_02.d
This line looks a little odd to me: assert(array.init==int.init); Aren't these incompatible types (int[2] and int)?
prints: int Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCOrd73w+/yD4P9tIRAvLfAKCpTnFRvLq9703Pd+SqrwklKImPngCcD2PQ GvXCxy48Gxz8bfR3c+IssPk= =jiMv -----END PGP SIGNATURE-----
Mar 18 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Thomas Kuehne wrote:
<snip>
This line looks a little odd to me:

     assert(array.init==int.init);

Aren't these incompatible types (int[2] and int)?
prints: int
That would seem to be itself a bug. http://www.digitalmars.com/d/property.html doesn't give any indication of arrays being a special case. If it was, then what would array.init be given this? int[2] array = [3, 5]; Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Mar 18 2005
parent reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stewart Gordon schrieb am Fri, 18 Mar 2005 12:06:03 +0000:
 Thomas Kuehne wrote:
<snip>
This line looks a little odd to me:

     assert(array.init==int.init);

Aren't these incompatible types (int[2] and int)?
prints: int
That would seem to be itself a bug. http://www.digitalmars.com/d/property.html doesn't give any indication of arrays being a special case. If it was, then what would array.init be given this? int[2] array = [3, 5];
Dynamic arrays are initialized as having zero elements. This isn't that usefull for .init Static arrays are initialized with a given element count, each element is initialized with the .init of the element's .init. Returning the element-init of each array element is the only usefull information the array-init can provide. All element types are equal, their inits are equal, thus the behaviour is legal. Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCOtSr3w+/yD4P9tIRAjanAJ43yo+tnPS2KfJ9lOcfuND/2EaxFACcD4ex WmNFL8VMPkc0TJf0yteUId0= =amtH -----END PGP SIGNATURE-----
Mar 18 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Thomas Kuehne wrote:
<snip>
 Dynamic arrays are initialized as having zero elements.
Only if you don't tell them otherwise.
 This isn't that usefull for .init
Maybe not directly, but certainly in generic programming.
 Static arrays are initialized with a given element count, each element
 is initialized with the .init of the element's .init. 
 Returning the element-init of each array element is the only usefull
 information the array-init can provide. 
Exactly.
 All element types are equal, their inits are equal, thus the behaviour is
 legal.
What are you referring to as "the behaviour" exactly? Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Mar 18 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
I for one am a little confused about how it's "supposed" to work.

I can't really see any documentation on the arrays page:
http://www.digitalmars.com/d/arrays.html

Here are my test cases:

import std.stdio;

void main()
{
	static int[]  array1 = [1,2,3,4];		
	//writefln("array1.init = ",typeid(typeof(array1.init)));   //Error:  
array initializers as expressions are not allowed
	writefln("array1[].init type   = ",typeid(typeof(array1[].init)));
	writefln("array1[0].init type  = ",typeid(typeof(array1[0].init)));
	writefln("array1[0].init       = ",array1[0].init);
	writefln("array1.length        = ",array1.length);
	writefln("array1[].init.length = ",array1[].init.length);
	writefln("");
	
	static int[4] array2 = [5,6,7,8];		
	//writefln("array2.init = ",typeid(typeof(array2.init)));   //Error:  
array initializers as expressions are not allowed
	writefln("array2[].init type   = ",typeid(typeof(array2[].init)));
	writefln("array2[0].init type  = ",typeid(typeof(array2[0].init)));
	writefln("array2[0].init       = ",array2[0].init);
	writefln("array2.length        = ",array2.length);
	writefln("array2[].init.length = ",array2[].init.length);
	writefln("");
	
	int[]  array3;
	writefln("array3.init type     = ",typeid(typeof(array3.init)));
	writefln("array3[].init type   = ",typeid(typeof(array3[].init)));
	writefln("array3[0].init type  = ",typeid(typeof(array3[0].init)));
	writefln("array3[0].init       = ",array3[0].init);
	writefln("array3.length        = ",array3.length);
	writefln("array3.init.length   = ",array3.init.length);
	writefln("array3[].init.length = ",array3[].init.length);
	writefln("");
	
	int[4] array4;
	writefln("array4.init type     = ",typeid(typeof(array4.init)));
	writefln("array4[].init type   = ",typeid(typeof(array4[].init)));
	writefln("array4[0].init type  = ",typeid(typeof(array4[0].init)));
	writefln("array4[0].init       = ",array4[0].init);
	writefln("array4.length        = ",array4.length);
	//writefln("array4.init.length   = ",array4.init.length);   //no property  
'length' for type 'int'
	writefln("array4[].init.length = ",array4[].init.length);
	writefln("");
}

Producing:

array1[].init type   = int[]
array1[0].init type  = int
array1[0].init       = 0
array1.length        = 4
array1[].init.length = 0

array2[].init type   = int[]
array2[0].init type  = int
array2[0].init       = 0
array2.length        = 4
array2[].init.length = 0

array3.init type     = int[]
array3[].init type   = int[]
array3[0].init type  = int
array3[0].init       = 0
array3.length        = 0
array3.init.length   = 0
array3[].init.length = 0

array4.init type     = int
array4[].init type   = int[]
array4[0].init type  = int
array4[0].init       = 0
array4.length        = 4
array4[].init.length = 0

Regan

On Fri, 18 Mar 2005 14:26:20 +0000, Stewart Gordon <smjg_1998 yahoo.com>  
wrote:

 Thomas Kuehne wrote:
 <snip>
 Dynamic arrays are initialized as having zero elements.
Only if you don't tell them otherwise.
 This isn't that usefull for .init
Maybe not directly, but certainly in generic programming.
 Static arrays are initialized with a given element count, each element
 is initialized with the .init of the element's .init. Returning the  
 element-init of each array element is the only usefull
 information the array-init can provide.
Exactly.
 All element types are equal, their inits are equal, thus the behaviour  
 is
 legal.
What are you referring to as "the behaviour" exactly? Stewart.
Mar 18 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Regan Heath wrote:
 I for one am a little confused about how it's "supposed" to work.
 
 I can't really see any documentation on the arrays page:
 http://www.digitalmars.com/d/arrays.html
The spec gives no special case for arrays. Hence .init works exactly the same.
 Here are my test cases:
 
 import std.stdio;
 
 void main()
 {
     static int[]  array1 = [1,2,3,4];       
     //writefln("array1.init = ",typeid(typeof(array1.init)));   
 //Error:  array initializers as expressions are not allowed
If there's any correct behaviour, it's that array1.init is an int[] containing the (length, pointer) tuple to which array1 was initialised. It follows that, if a given dynamic array's .init reference is used, then the GC must hold on to the initialisation data. Since the array's static, this could be done by keeping the initial data in the static data segment.
     writefln("array1[].init type   = ",typeid(typeof(array1[].init)));
     writefln("array1[0].init type  = ",typeid(typeof(array1[0].init)));
     writefln("array1[0].init       = ",array1[0].init);
     writefln("array1.length        = ",array1.length);
     writefln("array1[].init.length = ",array1[].init.length);
     writefln("");
     
     static int[4] array2 = [5,6,7,8];       
     //writefln("array2.init = ",typeid(typeof(array2.init)));   
 //Error:  array initializers as expressions are not allowed
That doesn't look right at all. It should be an int[4] containing the constant data [5,6,7,8].
     writefln("array2[].init type   = ",typeid(typeof(array2[].init)));
     writefln("array2[0].init type  = ",typeid(typeof(array2[0].init)));
     writefln("array2[0].init       = ",array2[0].init);
     writefln("array2.length        = ",array2.length);
     writefln("array2[].init.length = ",array2[].init.length);
     writefln("");
     
     int[]  array3;
     writefln("array3.init type     = ",typeid(typeof(array3.init)));
     writefln("array3[].init type   = ",typeid(typeof(array3[].init)));
     writefln("array3[0].init type  = ",typeid(typeof(array3[0].init)));
     writefln("array3[0].init       = ",array3[0].init);
     writefln("array3.length        = ",array3.length);
     writefln("array3.init.length   = ",array3.init.length);
     writefln("array3[].init.length = ",array3[].init.length);
     writefln("");
     
     int[4] array4;
     writefln("array4.init type     = ",typeid(typeof(array4.init)));
     writefln("array4[].init type   = ",typeid(typeof(array4[].init)));
     writefln("array4[0].init type  = ",typeid(typeof(array4[0].init)));
     writefln("array4[0].init       = ",array4[0].init);
     writefln("array4.length        = ",array4.length);
     //writefln("array4.init.length   = ",array4.init.length);   //no 
 property  'length' for type 'int'
This is wrong too.
     writefln("array4[].init.length = ",array4[].init.length);
     writefln("");
 }
 
 Producing:
 
 array1[].init type   = int[]
 array1[0].init type  = int
 array1[0].init       = 0
I guess it's debatable whether it makes sense to talk of the initialiser of an element or slice of a dynamic array. But the result is certainly wrong. Intuitively, it could defined such that array1[0].init == array1.init[0], which would be 1 in this case.
 array1.length        = 4
 array1[].init.length = 0
I don't get quite what DMD is making of this. But again, whatever it's doing is certainly bogus.
 array2[].init type   = int[]
 array2[0].init type  = int
 array2[0].init       = 0
 array2.length        = 4
 array2[].init.length = 0
Since static arrays are contained by value, their elements/slices are in effect variables in their own right, so it follows that all should be valid. But again, the zeros are wrong.
 array3.init type     = int[]
 array3[].init type   = int[]
 array3[0].init type  = int
 array3[0].init       = 0
 array3.length        = 0
 array3.init.length   = 0
 array3[].init.length = 0
<snip> These should behave in precisely the same ways as for the static case. But the fact that the array's initialiser is null in this case makes for a few differences. For once, array3.init.length is reported correctly, but array3[0].init should throw an ArrayBoundsError if it should be allowed at all. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Mar 21 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Mon, 21 Mar 2005 11:11:24 +0000, Stewart Gordon <smjg_1998 yahoo.com>  
wrote:
 Regan Heath wrote:
 I for one am a little confused about how it's "supposed" to work.
  I can't really see any documentation on the arrays page:
 http://www.digitalmars.com/d/arrays.html
The spec gives no special case for arrays. Hence .init works exactly the same.
 Here are my test cases:
  import std.stdio;
  void main()
 {
     static int[]  array1 = [1,2,3,4];           //writefln("array1.init  
 = ",typeid(typeof(array1.init)));   //Error:  array initializers as  
 expressions are not allowed
If there's any correct behaviour, it's that array1.init is an int[] containing the (length, pointer) tuple to which array1 was initialised.
Indeed. I was beginning to suspect at this point that DMD was replacing "array1.init" with "[1,2,3,4]" so my line: typeid(typeof(array2.init)) actually reads: typeid(typeof([5,6,7,8])) which is why it gives the error "array initializers as expressions are not allowed" This seems to be supported by the docs: file://localhost/C:/Library/D/dmd/html/d/property.html ".init produces a constant expression that is the default initializer." Walter can you verify/deny this and/or explain the error message?
   It follows that, if a given dynamic array's .init reference is used,  
 then the GC must hold on to the initialisation data.  Since the array's  
 static, this could be done by keeping the initial data in the static  
 data segment.
This is what I expected it to do, it appears to instead replace x.init with "a constant expression that is the default initializer."
     writefln("array2[].init type   = ",typeid(typeof(array2[].init)));
     writefln("array2[0].init type  = ",typeid(typeof(array2[0].init)));
     writefln("array2[0].init       = ",array2[0].init);
     writefln("array2.length        = ",array2.length);
     writefln("array2[].init.length = ",array2[].init.length);
     writefln("");
         int[]  array3;
     writefln("array3.init type     = ",typeid(typeof(array3.init)));
     writefln("array3[].init type   = ",typeid(typeof(array3[].init)));
     writefln("array3[0].init type  = ",typeid(typeof(array3[0].init)));
     writefln("array3[0].init       = ",array3[0].init);
     writefln("array3.length        = ",array3.length);
     writefln("array3.init.length   = ",array3.init.length);
     writefln("array3[].init.length = ",array3[].init.length);
     writefln("");
         int[4] array4;
     writefln("array4.init type     = ",typeid(typeof(array4.init)));
     writefln("array4[].init type   = ",typeid(typeof(array4[].init)));
     writefln("array4[0].init type  = ",typeid(typeof(array4[0].init)));
     writefln("array4[0].init       = ",array4[0].init);
     writefln("array4.length        = ",array4.length);
     //writefln("array4.init.length   = ",array4.init.length);   //no  
 property  'length' for type 'int'
This is wrong too.
Indeed. It seems to think array4.init is an 'int'. I would have expected an int[], or null reference. It could be argued that "int[4] array4" is the same as "int[4] array4 = 0", as arrays are initialised to 0. In which case the init value "0" is technically an 'int'.
     writefln("array4[].init.length = ",array4[].init.length);
     writefln("");
 }
  Producing:
  array1[].init type   = int[]
 array1[0].init type  = int
 array1[0].init       = 0
I guess it's debatable whether it makes sense to talk of the initialiser of an element or slice of a dynamic array.
Maybe. I wouldn't rule it out, someone is bound to think of a use for it. :)
 But the result is certainly wrong.
Indeed.
 Intuitively, it could defined such that array1[0].init ==  
 array1.init[0], which would be 1 in this case.
Agreed.
 array1.length        = 4
 array1[].init.length = 0
I don't get quite what DMD is making of this. But again, whatever it's doing is certainly bogus.
It makes no sense to me :)
 array2[].init type   = int[]
 array2[0].init type  = int
 array2[0].init       = 0
 array2.length        = 4
 array2[].init.length = 0
Since static arrays are contained by value, their elements/slices are in effect variables in their own right, so it follows that all should be valid. But again, the zeros are wrong.
Perhaps it is simply returning the .init value of the 'type' involved i.e. 'int'. Rather than the .init value of the instance of the int?
 array3.init type     = int[]
 array3[].init type   = int[]
 array3[0].init type  = int
 array3[0].init       = 0
 array3.length        = 0
 array3.init.length   = 0
 array3[].init.length = 0
<snip> These should behave in precisely the same ways as for the static case. But the fact that the array's initialiser is null in this case makes for a few differences. For once, array3.init.length is reported correctly,
I think that's a fluke given the previous behaviour :)
 but array3[0].init should throw an ArrayBoundsError if it should be  
 allowed at all.
Indeed. I expected the bounds error. Regan
Mar 21 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Regan Heath wrote:
<snip>
 Indeed. I was beginning to suspect at this point that DMD was replacing  
 "array1.init" with "[1,2,3,4]" so my line:
   typeid(typeof(array2.init))
 
 actually reads:
   typeid(typeof([5,6,7,8]))
 
 which is why it gives the error "array initializers as expressions are 
 not  allowed"
 
 This seems to be supported by the docs:
 file://localhost/C:/Library/D/dmd/html/d/property.html
None of us can access the files on your hard drive. <snip>
 It could be argued that "int[4] array4" is the same as "int[4] array4 =  
 0", as arrays are initialised to 0. In which case the init value "0" is  
 technically an 'int'.
Obviously 0 is an int. But we can't sensibly have the type of .init dependent on the syntax that was used to initialise it. All type.init properties should be of that type, and all variable.init properties should be the same type as the variable. <snip>
 Since static arrays are contained by value, their elements/slices are 
 in  effect variables in their own right, so it follows that all should 
 be  valid.  But again, the zeros are wrong.
Perhaps it is simply returning the .init value of the 'type' involved i.e. 'int'. Rather than the .init value of the instance of the int?
<snip> Yes, that is probably the essence of the bug. We could experiment with it further. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Mar 21 2005
parent "Regan Heath" <regan netwin.co.nz> writes:
On Mon, 21 Mar 2005 11:53:54 +0000, Stewart Gordon <smjg_1998 yahoo.com>  
wrote:
 Regan Heath wrote:
 <snip>
 Indeed. I was beginning to suspect at this point that DMD was  
 replacing  "array1.init" with "[1,2,3,4]" so my line:
   typeid(typeof(array2.init))
  actually reads:
   typeid(typeof([5,6,7,8]))
  which is why it gives the error "array initializers as expressions are  
 not  allowed"
  This seems to be supported by the docs:
 file://localhost/C:/Library/D/dmd/html/d/property.html
None of us can access the files on your hard drive.
LOL! <mumble>.. <mutter>.. <local copy>.. http://www.digitalmars.com/d/property.html
 <snip>
 It could be argued that "int[4] array4" is the same as "int[4] array4  
 =  0", as arrays are initialised to 0. In which case the init value "0"  
 is  technically an 'int'.
Obviously 0 is an int. But we can't sensibly have the type of .init dependent on the syntax that was used to initialise it. All type.init properties should be of that type, and all variable.init properties should be the same type as the variable.
I agree.. I was playing devils advocate again.
 <snip>
 Since static arrays are contained by value, their elements/slices are  
 in  effect variables in their own right, so it follows that all should  
 be  valid.  But again, the zeros are wrong.
Perhaps it is simply returning the .init value of the 'type' involved i.e. 'int'. Rather than the .init value of the instance of the int?
<snip> Yes, that is probably the essence of the bug. We could experiment with it further.
I rather hoped to attract Walters attention and save us the trouble. Regan
Mar 21 2005