[Issue 12625] implicit slicing of RValue static array should be illegal

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu May 8 02:32:18 PDT 2014


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

--- Comment #3 from Jonathan M Davis <jmdavisProg at gmx.com> ---
Well, per issue# 8838, we need to make slicing a static array - implicit or
otherwise - @system. As it stands, that's a huge hole in @safe. So, that
affects this on some level.

Regardless of whether implicit slicing takes place, I think that if there are
any situations where we can statically know that slicing a static array not
only unsafe, but it's guaranteed to be wrong, we should make that an error.
There's no reason to allow it. I don't know how easy it will be to enumerate
those cases and make them errors, but at minimum, as we find them, we should
make them errors.

I am 100% convinced that it was a huge mistake to make it so that static arrays
are ever implicitly sliced, so I would be very much in favor of deprecating
that and move towards removing it from the language, but it would break a lot
of code. I think that it's at least similar to the breakage caused by removing
implicit fallthrough in that it's highly bug-prone and as such is worth the
breakage, but I also don't think that it's wrong in anywhere near as many cases
as implicit fallthrough is, so the gain isn't as great. It's also probably far
more prevalent in code than switch statements are, so it's likely to be a hard
sell. A number of people have already balked at the idea of making slicing
static arrays @system even though it's a fact that that has to happen, or we
have a whole in @safe - there's no way around that (at best, we _might_ be able
to make it @safe in a few cases where scope was used - if scope were fully
implemented, which it's not). So, I'd expect a lot of folks to balk at this as
well. But I'm convinced that it would be worth it. The question is whether
enough people (and in particular, Walter and Andrei) can be convinced of that
as well.

But I definitely don't think that we should give up on this in that any case
where we know that it's guaranteed to be wrong, it should be an error. There's
no reason to allow it aside from the fact that we simply missed that particular
case (which should then be fixed when we find it).

--


More information about the Digitalmars-d-bugs mailing list