Fixed-size arrays and 'null'

Max Samukha spambox at d-coding.com
Fri Nov 13 08:08:09 PST 2009


On Thu, 12 Nov 2009 12:18:26 +0200, Max Samukha <spambox at d-coding.com>
wrote:

>Please consider the following: 
>
>import std.stdio;
>
>void foo(int[3] a) {}
>
>void main()
>{
>    int[3] a = null; // 1
>    a = null; // 2
>    foo(null); // 3
>    if (a is null){} // 4
>    if (a == null){} // 5
>}
>
>1 - 2. These compile and issue runtime error. null is implicitly cast
>to int[] and the program tries to assign it at runtime. Even if it is
>not a bug, the error can be detected at compile-time.
>
>3. Fails, but if 1-2 are ok, I can't see why.
>
>4. Compiles but makes little sense.
>
>5. This may be ok, if 1-2 are ok.
>
>I think all of the above should fail at compile time. Just disallow
>null initialization/assignment/comparison for fixed-size arrays.
>
>The new behavior has broken some of my code relying on a type's
>nullability and I would like to know if the semantics are officially
>approved (provided 3 and 4 are fixed)?

Since nobody else has anything to say about this, I assume it is a
bug.



More information about the Digitalmars-d mailing list