This is mistake.
Although the definition of an array and the expression of a range have different concepts (you cannot use a.[1..2..5]
, for example), they should behave sequentially.
Note that the exception occurs with a.[start..finish]
when finish - start <= -2
( a.[3..1]
does not work), and an array slice works fine if finish - start = -1
( a.[5..4] = [||]
).
Array slicing is done using GetArraySlice in prim-types.fs :
let inline GetArraySlice (arr: _[]) start finish = let start = (match start with None -> 0 | Some n -> n) let finish = (match finish with None -> arr.Length - 1 | Some n -> n) GetArraySub arr start (finish - start + 1)
whereas GetArraySub
is implemented in the same module as follows:
let inline GetArraySub arr (start:int) (len:int) = let dst = zeroCreate len for i = 0 to len - 1 do SetArray dst i (GetArray arr (start + i)) dst
If finish - start = -1
, we have len = 0
in GetArraySub
, and zeroCreate 0
returns an empty array. This is no longer the case with finish - start <= -2
, which results in len < 0
and zeroCreate len
fails.
This can be fixed by always returning an empty array whenever finish - start <= -1
.
source share