parent
c94933acb7
commit
018465a234
2 changed files with 12 additions and 1 deletions
|
|
@ -920,7 +920,7 @@ proc genArrayElem(p: BProc, n, x, y: PNode, d: var TLoc) =
|
||||||
if optBoundsCheck in p.options and ty.kind != tyUncheckedArray:
|
if optBoundsCheck in p.options and ty.kind != tyUncheckedArray:
|
||||||
if not isConstExpr(y):
|
if not isConstExpr(y):
|
||||||
# semantic pass has already checked for const index expressions
|
# semantic pass has already checked for const index expressions
|
||||||
if firstOrd(p.config, ty) == 0:
|
if firstOrd(p.config, ty) == 0 and lastOrd(p.config, ty) >= 0:
|
||||||
if (firstOrd(p.config, b.t) < firstOrd(p.config, ty)) or (lastOrd(p.config, b.t) > lastOrd(p.config, ty)):
|
if (firstOrd(p.config, b.t) < firstOrd(p.config, ty)) or (lastOrd(p.config, b.t) > lastOrd(p.config, ty)):
|
||||||
linefmt(p, cpsStmts, "if ((NU)($1) > (NU)($2)){ #raiseIndexError2($1, $2); $3}$n",
|
linefmt(p, cpsStmts, "if ((NU)($1) > (NU)($2)){ #raiseIndexError2($1, $2); $3}$n",
|
||||||
[rdCharLoc(b), intLiteral(lastOrd(p.config, ty)), raiseInstr(p)])
|
[rdCharLoc(b), intLiteral(lastOrd(p.config, ty)), raiseInstr(p)])
|
||||||
|
|
|
||||||
|
|
@ -594,3 +594,14 @@ block t17705:
|
||||||
a = int(a)
|
a = int(a)
|
||||||
var b = array[0, int].high
|
var b = array[0, int].high
|
||||||
b = int(b)
|
b = int(b)
|
||||||
|
|
||||||
|
block t18643:
|
||||||
|
# https://github.com/nim-lang/Nim/issues/18643
|
||||||
|
let a: array[0, int] = []
|
||||||
|
var caught = false
|
||||||
|
let b = 9999999
|
||||||
|
try:
|
||||||
|
echo a[b]
|
||||||
|
except IndexDefect:
|
||||||
|
caught = true
|
||||||
|
doAssert caught, "IndexDefect not caught!"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue