summary refs log tree commit diff stats
path: root/compiler/semfold.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2019-02-10 13:07:11 -0800
committerAndreas Rumpf <rumpf_a@web.de>2019-02-13 23:30:14 +0100
commit942495611b266bc81dc4374e914fa990f3c2d6a2 (patch)
tree719a4eaa1a1d795a7df110744b282b98ac3db757 /compiler/semfold.nim
parent8f05b3412568ec66a72bcae221613630d561aac0 (diff)
downloadNim-942495611b266bc81dc4374e914fa990f3c2d6a2.tar.gz
revive #10228 (fix #9880) (#10610)
* Make index out of bounds more useful by including the 'bounds'.
* fixes #9880 index out of bounds (remaining cases); revives #10228
* change err msg to: `index 3 not in 0 .. 1`
Diffstat (limited to 'compiler/semfold.nim')
-rw-r--r--compiler/semfold.nim4
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index 237a5127a..f0b03018f 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -493,11 +493,11 @@ proc foldArrayAccess(m: PSym, n: PNode; g: ModuleGraph): PNode =
       result = x.sons[int(idx)]
       if result.kind == nkExprColonExpr: result = result.sons[1]
     else:
-      localError(g.config, n.info, formatErrorIndexBound(idx, sonsLen(x)+1) & $n)
+      localError(g.config, n.info, formatErrorIndexBound(idx, sonsLen(x)-1) & $n)
   of nkBracket:
     idx = idx - firstOrd(g.config, x.typ)
     if idx >= 0 and idx < x.len: result = x.sons[int(idx)]
-    else: localError(g.config, n.info, formatErrorIndexBound(idx, x.len+1) & $n)
+    else: localError(g.config, n.info, formatErrorIndexBound(idx, x.len-1) & $n)
   of nkStrLit..nkTripleStrLit:
     result = newNodeIT(nkCharLit, x.info, n.typ)
     if idx >= 0 and idx < len(x.strVal):