* 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`
This commit is contained in:
parent
8f05b34125
commit
942495611b
11 changed files with 88 additions and 36 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue