On Tue, 06 Mar 2012 20:27:56 +0100, H. S. Teoh <hst...@quickfur.ath.cx> wrote:

Code:

        // test.d
        class A {}
        class B : A {}
        class C : A {}
        void main() {
                A[] objs = [ new B, new C ];    // line 6
        }

Compiler error:

test.d(6): Error: cannot implicitly convert expression (new B) of type test.A to test.C test.d(6): Error: cannot implicitly convert expression ([(__error),new C]) of type C[] to A[]

I thought D was supposed to automatically infer the most derived common
base class to assign to an array literal of different types? At least,
that's the impression I got from TDPL.

What am I doing wrong?


T


I have no idea (and haven't read TDPL), but adding a new A somewhere in the array makes it work. Compiler bug..?

Reply via email to