summary refs log tree commit diff stats
path: root/tests/misc
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 /tests/misc
parent7a66616d741106d4c18ce2e8f843a8b5d31f6025 (diff)
downloadNim-f3ecc15a94c12b149f0665d250af1d71dd128721.tar.gz
refs #9880 show index and bound in lots of `index out of bounds` errors
Diffstat (limited to 'tests/misc')
-rw-r--r--tests/misc/tinvalidarrayaccess.nim25
-rw-r--r--tests/misc/tinvalidarrayaccess2.nim16
2 files changed, 32 insertions, 9 deletions
diff --git a/tests/misc/tinvalidarrayaccess.nim b/tests/misc/tinvalidarrayaccess.nim
index 03105b41b..57ad38b85 100644
--- a/tests/misc/tinvalidarrayaccess.nim
+++ b/tests/misc/tinvalidarrayaccess.nim
@@ -1,14 +1,21 @@
 discard """
-  errormsg: "index out of bounds"
-  line: 11
+  errormsg: "index out of bounds: (a:0) <= (i:2) <= (b:1) "
+  line: 18
 """
 
+block:
+  try:
+    let a = @[1,2]
+    echo a[3]
+  except Exception as e:
+    doAssert e.msg == "index out of bounds: (i:3) <= (n:1) "
 
-type TTestArr = array[0..1, int16]
-var f: TTestArr
-f[0] = 30
-f[1] = 40
-f[2] = 50
-f[3] = 60
+block:
+  type TTestArr = array[0..1, int16]
+  var f: TTestArr
+  f[0] = 30
+  f[1] = 40
+  f[2] = 50
+  f[3] = 60
 
-echo(repr(f))
+  echo(repr(f))
diff --git a/tests/misc/tinvalidarrayaccess2.nim b/tests/misc/tinvalidarrayaccess2.nim
new file mode 100644
index 000000000..86d349457
--- /dev/null
+++ b/tests/misc/tinvalidarrayaccess2.nim
@@ -0,0 +1,16 @@
+discard """
+  errormsg: "index out of bounds: (a:0) <= (i:3) <= (b:1) "
+  line: 9
+"""
+
+# Note: merge in tinvalidarrayaccess.nim pending https://github.com/nim-lang/Nim/issues/9906
+
+let a = [1,2]
+echo a[3]
+
+when false:
+  # TOOD: this case is not yet handled, giving: "index out of bounds"
+  proc fun()=
+    let a = @[1,2]
+    echo a[3]
+  static: fun()