Skip to content

Commit

Permalink
fixes #22852 and adds a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Feb 2, 2024
1 parent 83deb67 commit c47b28c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/system/indices.nim
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,8 @@ proc `[]`*[Idx, T; U, V: Ordinal](a: array[Idx, T], x: HSlice[U, V]): seq[T] {.s
## ```
let xa = a ^^ x.a
let L = (a ^^ x.b) - xa + 1
# Workaround bug #22852:
result = newSeq[T](if L < 0: 0 else: L)
result = newSeq[T](L)
for i in 0..<L: result[i] = a[Idx(i + xa)]
# Workaround bug #22852
discard Natural(L)

proc `[]=`*[Idx, T; U, V: Ordinal](a: var array[Idx, T], x: HSlice[U, V], b: openArray[T]) {.systemRaisesDefect.} =
## Slice assignment for arrays.
Expand Down
9 changes: 9 additions & 0 deletions tests/errmsgs/t22852.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
discard """
exitcode: 1
outputsub: '''
Error: unhandled exception: value out of range: -2 notin 0 .. 9223372036854775807 [RangeDefect]
'''
"""

# bug #22852
echo [0][2..^2]

0 comments on commit c47b28c

Please sign in to comment.