[Issue 15932] Get rid of the implicit slicing of static arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 15 16:45:59 UTC 2022


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

--- Comment #5 from hsteoh at qfbox.info ---
I don't see what's so hard about adding `[]` to a static array before passing
it to Phobos.  Even in generic code where you could argue that the incoming
type could be either static or dynamic array, you can still write `[]` and it
would still work (a slice of a dynamic array is still the same dynamic array,
there is no problem there).

This is what Andrei complained about, we bend over backwards to support use
cases that weren't intended to be supported, and pretty soon we end up with a
ridiculous amount of cruft that didn't even need to be there in the first
place. Asking the user to write 2 extra characters is a much simpler and better
solution than introducing silent ways to shoot themselves in the foot because
they didn't realize what was happening under the hood.  I have been bitten by
this specific issue (implicit conversion of static array to dynamic) more than
once, the headache in debugging the issue -- because it's implicit and
therefore hard to find -- is so not worth the non-existent "cost" of writing
two extra characters.  I would have much preferred that the compiler refused to
compile the code to bring my attention to the fact that I'm dealing with a
static array, than to silently accept static arrays with unexpected semantics
that lead to bugs down the road.

--


More information about the Digitalmars-d-bugs mailing list