The following code compiles and shouldn't: struct Foo { double num; } void main() { Foo[] foo = new Foo[5]; foo[] = null; } It then fails at runtime with the following nonsensical error message: object.Exception: lengths don't match for array copy
It's an example of bug 3889
null is a valid value for a slice, and the rvalue of the assignment is expected to be a slice. It's a slice with 0 length (which is still a valid slice), and for slice assignment to work the length of the lvalue must match the length of the rvalue. The message is correct - the lengths don't match. This is working as designed.
Bearophile is correct that this is a duplicate of bug 3889, which is an enhancement request.
I'd rather say it's a dup of bug 3395.
Disambiguation will make it hard to copy empty slices... well... such operation is not needed too much either. --- foo[]=(cast(Foo[])null)[]; //copy null slice foo[]=null; //should not typecheck, expected foo[]=Foo(...); ---