Type inference in array literals

Jesse Phillips jessekphillips+D at gmail.com
Sat Aug 28 09:19:30 PDT 2010

D uses the last element in the array literal to select the type. I think there was a discussion on why a common type wasn't used, but don't remember the conclusion. It would be nice if it used the item you are assigning to and check they can convert to it.

klickverbot Wrote:

> I was really surprised by the fact that the following code does not work 
> (DMD 2.048 infers the type of the array literal to B[], not Object[]):
> ---
> class A {}
> class B {}
> void main() {
>     Object[] foo = [ new A, new B ];
> }

More information about the Digitalmars-d mailing list