summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/system/indices.nim2
-rw-r--r--tests/errmsgs/t23435.nim12
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/system/indices.nim b/lib/system/indices.nim
index fb6151a74..e1ac68383 100644
--- a/lib/system/indices.nim
+++ b/lib/system/indices.nim
@@ -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)
diff --git a/tests/errmsgs/t23435.nim b/tests/errmsgs/t23435.nim
new file mode 100644
index 000000000..5e2e4c82a
--- /dev/null
+++ b/tests/errmsgs/t23435.nim
@@ -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()