Fix reverse on empty openArray (#5407)

Reversing an empty `openArray` would raise a RangeError. For instance for `a: seq[int] = @[]`, we have `a.high` return `-1` but `-1` is not a `Natural`. Leaving the array as-is is the expected behaviour.
This commit is contained in:
fenekku
2017-02-17 02:26:49 -05:00
committed by Andreas Rumpf
parent 9534a5d632
commit e9767d8809

View File

@@ -46,7 +46,7 @@ proc reverse*[T](a: var openArray[T], first, last: Natural) =
proc reverse*[T](a: var openArray[T]) =
## reverses the array `a`.
reverse(a, 0, a.high)
reverse(a, 0, max(0, a.high))
proc reversed*[T](a: openArray[T], first: Natural, last: int): seq[T] =
## returns the reverse of the array `a[first..last]`.