workaround #23435; real fix pending #23279 (#23436)

workaround #23435

related to https://github.com/nim-lang/Nim/issues/22852

see also #23279
This commit is contained in:
ringabout
2024-04-19 03:55:26 +08:00
committed by GitHub
parent 2a7ddcab2d
commit 229c125d2f
2 changed files with 14 additions and 0 deletions

View File

@@ -80,6 +80,8 @@ proc `[]`*[T, U: Ordinal](s: string, x: HSlice[T, U]): string {.inline, systemRa
## var s = "abcdef"
## assert s[1..3] == "bcd"
## ```
# Workaround bug #22852
result = ""
let a = s ^^ x.a
let L = (s ^^ x.b) - a + 1
result = newString(L)

12
tests/errmsgs/t23435.nim Normal file
View File

@@ -0,0 +1,12 @@
discard """
outputsub: "Error: unhandled exception: value out of range: -15 notin 0 .. 9223372036854775807 [RangeDefect]"
exitcode: "1"
"""
# bug #23435
proc foo() =
for _ in @[1, 3, 5]:
discard "abcde"[25..<10]
break
foo()