Better range error messages (#19867)
* Better range error messages * Revert to old behavior for arrays * Small corrections
This commit is contained in:
parent
e7e8f437c4
commit
d33e112766
2 changed files with 6 additions and 3 deletions
|
|
@ -988,12 +988,12 @@ proc genBoundsCheck(p: BProc; arr, a, b: TLoc) =
|
||||||
if reifiedOpenArray(arr.lode):
|
if reifiedOpenArray(arr.lode):
|
||||||
linefmt(p, cpsStmts,
|
linefmt(p, cpsStmts,
|
||||||
"if ($2-$1 != -1 && " &
|
"if ($2-$1 != -1 && " &
|
||||||
"($1 < 0 || $1 >= $3.Field1 || $2 < 0 || $2 >= $3.Field1)){ #raiseIndexError(); $4}$n",
|
"($1 < 0 || $1 >= $3.Field1 || $2 < 0 || $2 >= $3.Field1)){ #raiseIndexError4($1, $2, $3.Field1); $4}$n",
|
||||||
[rdLoc(a), rdLoc(b), rdLoc(arr), raiseInstr(p)])
|
[rdLoc(a), rdLoc(b), rdLoc(arr), raiseInstr(p)])
|
||||||
else:
|
else:
|
||||||
linefmt(p, cpsStmts,
|
linefmt(p, cpsStmts,
|
||||||
"if ($2-$1 != -1 && ($1 < 0 || $1 >= $3Len_0 || $2 < 0 || $2 >= $3Len_0))" &
|
"if ($2-$1 != -1 && ($1 < 0 || $1 >= $3Len_0 || $2 < 0 || $2 >= $3Len_0))" &
|
||||||
"{ #raiseIndexError(); $4}$n",
|
"{ #raiseIndexError4($1, $2, $3Len_0); $4}$n",
|
||||||
[rdLoc(a), rdLoc(b), rdLoc(arr), raiseInstr(p)])
|
[rdLoc(a), rdLoc(b), rdLoc(arr), raiseInstr(p)])
|
||||||
of tyArray:
|
of tyArray:
|
||||||
let first = intLiteral(firstOrd(p.config, ty))
|
let first = intLiteral(firstOrd(p.config, ty))
|
||||||
|
|
@ -1004,7 +1004,7 @@ proc genBoundsCheck(p: BProc; arr, a, b: TLoc) =
|
||||||
of tySequence, tyString:
|
of tySequence, tyString:
|
||||||
linefmt(p, cpsStmts,
|
linefmt(p, cpsStmts,
|
||||||
"if ($2-$1 != -1 && " &
|
"if ($2-$1 != -1 && " &
|
||||||
"($1 < 0 || $1 >= $3 || $2 < 0 || $2 >= $3)){ #raiseIndexError(); $4}$n",
|
"($1 < 0 || $1 >= $3 || $2 < 0 || $2 >= $3)){ #raiseIndexError4($1, $2, $3); $4}$n",
|
||||||
[rdLoc(a), rdLoc(b), lenExpr(p, arr), raiseInstr(p)])
|
[rdLoc(a), rdLoc(b), lenExpr(p, arr), raiseInstr(p)])
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ proc raiseRangeError(val: BiggestInt) {.compilerproc, noinline.} =
|
||||||
else:
|
else:
|
||||||
sysFatal(RangeDefect, "value out of range: ", $val)
|
sysFatal(RangeDefect, "value out of range: ", $val)
|
||||||
|
|
||||||
|
proc raiseIndexError4(l1, h1, h2: int) {.compilerproc, noinline.} =
|
||||||
|
sysFatal(IndexDefect, "index out of bounds: " & $l1 & ".." & $h1 & " notin 0.." & $(h2 - 1))
|
||||||
|
|
||||||
proc raiseIndexError3(i, a, b: int) {.compilerproc, noinline.} =
|
proc raiseIndexError3(i, a, b: int) {.compilerproc, noinline.} =
|
||||||
sysFatal(IndexDefect, formatErrorIndexBound(i, a, b))
|
sysFatal(IndexDefect, formatErrorIndexBound(i, a, b))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue