20461, "vasslitvinov", "range slicing: how to report an error?", "2022-08-17T05:17:52Z"
The result of Range slicing may produce an error in the cases where the result is not representable within the static type of the result. For example:
r1 type
r2 type
r1(r2) type
can't represent
(int, boundedLow, stridable)
same
same
(1.. by 2 align 0) (1.. by 2 align 1)
(int(8), boundedLow)
(int, boundedLow)
(int(8), boundedLow)
(1:int(8)..) (256..)
(int, boundedNone, stridable)
same
same
(.. by 2) (.. by 4)
This issue asks: what should the program do if one of these situations occurs?
halt
halt if boundsChecks are on, produce garbage otherwise
throw an exception regardless of boundsChecks
ditto, with this refinement: provide a non-throwing overload of the slicing implementation for those cases where we know statically that none of these errors can occur
Notes
In some cases the intersection of the two ranges is semantically an empty set of indices. In some of these cases the slicing implementation produces the empty range 1..0.
With today's implementation, the first and the third examples in the above table halt the program; the second example produces 0... The answer 0.. is incorrect for the second example. The third example should probably be representable and produce .. by 4.