dmd 2.057 release

Walter Bright newshound2 at digitalmars.com
Wed Dec 14 02:10:32 PST 2011


On 12/14/2011 1:59 AM, Jacob Carlborg wrote:
> What happened to arrays in this release:
>
> void foo (Object[] a) {}
> class Foo {}
>
> void main ()
> {
> Foo[] b;
> foo(b);
> }
>
> The above code fails with the following message:
>
> main.d(54): Error: function main.foo (Object[] a) is not callable using argument
> types (Foo[])
> main.d(54): Error: cannot implicitly convert expression (b) of type Foo[] to
> Object[]
>
> Have I missed something, I can't find this in the changelog?

I don't remember if there was a bugzilla entry for it, but it's the object 
slicing problem. The thing is, main() expects b to be an array of Foo's. If 
foo() replaces one of the array elements with an Object, then b is no longer an 
array of Foo's, and can crash.

Note that if you write foo as:

     void foo(const(Object)[] a)

it will work.


More information about the Digitalmars-d-announce mailing list