[Issue 6346] Make == null a warning for arrays

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Aug 7 11:04:22 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=6346

--- Comment #11 from Jonathan M Davis <jmdavisProg at gmx.com> ---
(In reply to Orvid King from comment #10)
> Not sure, but isn't this currently an error?

No. It's perfectly legal to compare against null. null is basically the same as
[]. As far as the compiler is concerned, in the context of arrays, null is just
an empty array. IMHO, it's very frustrating that that's the case, but we're
stuck with it at this point.

And I should probably just close this issue. Due to how the compiler tries to
treat null as the same an empty array in almost all contexts, even trying to
distinguish between a null array and an empty one is tricky and error-prone -
to the point that if you really want a null array, it would arguably be better
to wrap it in a Nullable, which is kind of silly IMHO, since arrays _are_
nullable, but since the compiler only treats null as special _some_ of the
time, you have to be very careful if you want to treat it as special.

--


More information about the Digitalmars-d-bugs mailing list