www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Array type inference

reply "James Miller" <james aatch.net> writes:
I am using an array of objects, all of which have a common type 
(They are all sub classes of Field). If I declare an array of 
these objects, D seems to try to cast them all to the last type 
in the array, rather than picking a common supertype. This 
happens even if I specify a type for the array, D still doesn't 
cast the types properly.

In the error message it also seems that it casts _some_ types 
properly, but others not, resulting in some very strange error 
messages. I can work around this by casting all of the elements 
to the common supertype, but this is not ideal.

Is this a known bug, expected functionality, or should I file a 
bug request?

--
James Miller
May 03 2012
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Friday, May 04, 2012 08:33:32 James Miller wrote:
 I am using an array of objects, all of which have a common type
 (They are all sub classes of Field). If I declare an array of
 these objects, D seems to try to cast them all to the last type
 in the array, rather than picking a common supertype. This
 happens even if I specify a type for the array, D still doesn't
 cast the types properly.
 
 In the error message it also seems that it casts _some_ types
 properly, but others not, resulting in some very strange error
 messages. I can work around this by casting all of the elements
 to the common supertype, but this is not ideal.
 
 Is this a known bug, expected functionality, or should I file a
 bug request?
http://d.puremagic.com/issues/show_bug.cgi?id=5498 - Jonathan M Davis
May 03 2012