Why do array literals default to object.Object[]?

Brandon Buck via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 11 22:24:49 PDT 2017


On Wednesday, 12 July 2017 at 02:06:41 UTC, Steven Schveighoffer 
wrote:
> I do agree it's not intuitive for an initializer, especially 
> when:
>
> auto a = [1, 2, 3]; // typeof(a) == int[]
> short[] b = [1, 2, 3]; // works

Thank you for getting back to me, that's where my train of 
thought was going. While I know it's not _really_ valid to say 
"this other language does it," my experience does hail from 
elsewhere where this would be perfectly legal.

> I'm sure there's a bug filed somewhere on this...

Is this bug worthy? I can search for one and comment and/or 
create one if I can't find one.

> auto d = new Dog;
> Animal a = d;
> writefln("%x, %x", cast(void*)d, cast(void*)a); // prints 2 
> different addresses

That's also an interesting observation.



More information about the Digitalmars-d-learn mailing list