summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2018-12-06 15:42:44 -0800
committerTimothee Cour <timothee.cour2@gmail.com>2018-12-09 16:50:45 -0800
commitf3ecc15a94c12b149f0665d250af1d71dd128721 (patch)
tree5ddd43e4b49bbd6ef72625fdbcd0c5864dc74748 /lib/system
parent7a66616d741106d4c18ce2e8f843a8b5d31f6025 (diff)
downloadNim-f3ecc15a94c12b149f0665d250af1d71dd128721.tar.gz
refs #9880 show index and bound in lots of `index out of bounds` errors
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/chcks.nim9
-rw-r--r--lib/system/helpers2.nim5
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/system/chcks.nim b/lib/system/chcks.nim
index d3651f659..6f4e8ce37 100644
--- a/lib/system/chcks.nim
+++ b/lib/system/chcks.nim
@@ -8,6 +8,7 @@
 #
 
 # Implementation of some runtime checks.
+import system/helpers2
 
 proc raiseRangeError(val: BiggestInt) {.compilerproc, noinline.} =
   when hostOS == "standalone":
@@ -15,6 +16,12 @@ proc raiseRangeError(val: BiggestInt) {.compilerproc, noinline.} =
   else:
     sysFatal(RangeError, "value out of range: ", $val)
 
+proc raiseIndexError3(i, a, b: int) {.compilerproc, noinline.} =
+  sysFatal(IndexError, formatErrorIndexBound(i, a, b))
+
+proc raiseIndexError2(i, n: int) {.compilerproc, noinline.} =
+  sysFatal(IndexError, formatErrorIndexBound(i, n))
+
 proc raiseIndexError() {.compilerproc, noinline.} =
   sysFatal(IndexError, "index out of bounds")
 
@@ -25,7 +32,7 @@ proc chckIndx(i, a, b: int): int =
   if i >= a and i <= b:
     return i
   else:
-    raiseIndexError()
+    raiseIndexError3(i, a, b)
 
 proc chckRange(i, a, b: int): int =
   if i >= a and i <= b:
diff --git a/lib/system/helpers2.nim b/lib/system/helpers2.nim
new file mode 100644
index 000000000..1c9e7c068
--- /dev/null
+++ b/lib/system/helpers2.nim
@@ -0,0 +1,5 @@
+template formatErrorIndexBound*[T](i, a, b: T): string =
+  "index out of bounds: (a:" & $a & ") <= (i:" & $i & ") <= (b:" & $b & ") "
+
+template formatErrorIndexBound*[T](i, n: T): string =
+  "index out of bounds: (i:" & $i & ") <= (n:" & $n & ") "