mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-15 03:52:44 +00:00
Error -> Defect for defects (#13908)
* Error -> Defect for defects The distinction between Error and Defect is subjective, context-dependent and somewhat arbitrary, so when looking at an exception, it's hard to guess what it is - this happens often when looking at a `raises` list _without_ opening the corresponding definition and digging through layers of inheritance. With the help of a little consistency in naming, it's at least possible to start disentangling the two error types and the standard lib can set a good example here.
This commit is contained in:
@@ -290,7 +290,7 @@ type
|
|||||||
sfTemplateParam # symbol is a template parameter
|
sfTemplateParam # symbol is a template parameter
|
||||||
sfCursor # variable/field is a cursor, see RFC 177 for details
|
sfCursor # variable/field is a cursor, see RFC 177 for details
|
||||||
sfInjectDestructors # whether the proc needs the 'injectdestructors' transformation
|
sfInjectDestructors # whether the proc needs the 'injectdestructors' transformation
|
||||||
sfNeverRaises # proc can never raise an exception, not even OverflowError
|
sfNeverRaises # proc can never raise an exception, not even OverflowDefect
|
||||||
# or out-of-memory
|
# or out-of-memory
|
||||||
|
|
||||||
TSymFlags* = set[TSymFlag]
|
TSymFlags* = set[TSymFlag]
|
||||||
|
|||||||
@@ -821,7 +821,7 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) =
|
|||||||
v.r.add(".")
|
v.r.add(".")
|
||||||
v.r.add(disc.sym.loc.r)
|
v.r.add(disc.sym.loc.r)
|
||||||
genInExprAux(p, it, u, v, test)
|
genInExprAux(p, it, u, v, test)
|
||||||
let msg = genFieldError(field, disc.sym)
|
let msg = genFieldDefect(field, disc.sym)
|
||||||
let strLit = genStringLiteral(p.module, newStrNode(nkStrLit, msg))
|
let strLit = genStringLiteral(p.module, newStrNode(nkStrLit, msg))
|
||||||
if op.magic == mNot:
|
if op.magic == mNot:
|
||||||
linefmt(p, cpsStmts,
|
linefmt(p, cpsStmts,
|
||||||
|
|||||||
@@ -1131,7 +1131,7 @@ proc genCheckedFieldOp(p: PProc, n: PNode, addrTyp: PType, r: var TCompRes) =
|
|||||||
|
|
||||||
useMagic(p, "raiseFieldError")
|
useMagic(p, "raiseFieldError")
|
||||||
useMagic(p, "makeNimstrLit")
|
useMagic(p, "makeNimstrLit")
|
||||||
let msg = genFieldError(field, disc)
|
let msg = genFieldDefect(field, disc)
|
||||||
lineF(p, "if ($1[$2.$3]$4undefined) { raiseFieldError(makeNimstrLit($5)); }$n",
|
lineF(p, "if ($1[$2.$3]$4undefined) { raiseFieldError(makeNimstrLit($5)); }$n",
|
||||||
setx.res, tmp, disc.loc.r, if negCheck: ~"!==" else: ~"===",
|
setx.res, tmp, disc.loc.r, if negCheck: ~"!==" else: ~"===",
|
||||||
makeJSString(msg))
|
makeJSString(msg))
|
||||||
@@ -2343,7 +2343,7 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) =
|
|||||||
if r.kind != resCallee: r.kind = resNone
|
if r.kind != resCallee: r.kind = resNone
|
||||||
#r.address = nil
|
#r.address = nil
|
||||||
r.res = nil
|
r.res = nil
|
||||||
|
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkSym:
|
of nkSym:
|
||||||
genSym(p, n, r)
|
genSym(p, n, r)
|
||||||
@@ -2398,7 +2398,7 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) =
|
|||||||
n.len >= 1:
|
n.len >= 1:
|
||||||
genInfixCall(p, n, r)
|
genInfixCall(p, n, r)
|
||||||
else:
|
else:
|
||||||
genCall(p, n, r)
|
genCall(p, n, r)
|
||||||
of nkClosure: gen(p, n[0], r)
|
of nkClosure: gen(p, n[0], r)
|
||||||
of nkCurly: genSetConstr(p, n, r)
|
of nkCurly: genSetConstr(p, n, r)
|
||||||
of nkBracket: genArrayConstr(p, n, r)
|
of nkBracket: genArrayConstr(p, n, r)
|
||||||
@@ -2602,7 +2602,7 @@ proc myClose(graph: ModuleGraph; b: PPassContext, n: PNode): PNode =
|
|||||||
(code, map) = genSourceMap($(code), outFile.string)
|
(code, map) = genSourceMap($(code), outFile.string)
|
||||||
writeFile(outFile.string & ".map", $(%map))
|
writeFile(outFile.string & ".map", $(%map))
|
||||||
discard writeRopeIfNotEqual(code, outFile)
|
discard writeRopeIfNotEqual(code, outFile)
|
||||||
|
|
||||||
proc myOpen(graph: ModuleGraph; s: PSym): PPassContext =
|
proc myOpen(graph: ModuleGraph; s: PSym): PPassContext =
|
||||||
result = newModule(graph, s)
|
result = newModule(graph, s)
|
||||||
|
|
||||||
|
|||||||
@@ -571,7 +571,7 @@ proc getNumber(L: var TLexer, result: var TToken) =
|
|||||||
try:
|
try:
|
||||||
len = parseBiggestUInt(result.literal, iNumber)
|
len = parseBiggestUInt(result.literal, iNumber)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise newException(OverflowError, "number out of range: " & $result.literal)
|
raise newException(OverflowDefect, "number out of range: " & $result.literal)
|
||||||
if len != result.literal.len:
|
if len != result.literal.len:
|
||||||
raise newException(ValueError, "invalid integer: " & $result.literal)
|
raise newException(ValueError, "invalid integer: " & $result.literal)
|
||||||
result.iNumber = cast[int64](iNumber)
|
result.iNumber = cast[int64](iNumber)
|
||||||
@@ -581,7 +581,7 @@ proc getNumber(L: var TLexer, result: var TToken) =
|
|||||||
try:
|
try:
|
||||||
len = parseBiggestInt(result.literal, iNumber)
|
len = parseBiggestInt(result.literal, iNumber)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise newException(OverflowError, "number out of range: " & $result.literal)
|
raise newException(OverflowDefect, "number out of range: " & $result.literal)
|
||||||
if len != result.literal.len:
|
if len != result.literal.len:
|
||||||
raise newException(ValueError, "invalid integer: " & $result.literal)
|
raise newException(ValueError, "invalid integer: " & $result.literal)
|
||||||
result.iNumber = iNumber
|
result.iNumber = iNumber
|
||||||
@@ -607,7 +607,7 @@ proc getNumber(L: var TLexer, result: var TToken) =
|
|||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
lexMessageLitNum(L, "invalid number: '$1'", startpos)
|
lexMessageLitNum(L, "invalid number: '$1'", startpos)
|
||||||
except OverflowError, RangeError:
|
except OverflowDefect, RangeDefect:
|
||||||
lexMessageLitNum(L, "number out of range: '$1'", startpos)
|
lexMessageLitNum(L, "number out of range: '$1'", startpos)
|
||||||
tokenEnd(result, postPos-1)
|
tokenEnd(result, postPos-1)
|
||||||
L.bufpos = postPos
|
L.bufpos = postPos
|
||||||
|
|||||||
@@ -1599,9 +1599,9 @@ proc quoteExpr*(a: string): string {.inline.} =
|
|||||||
## can be used for quoting expressions in error msgs.
|
## can be used for quoting expressions in error msgs.
|
||||||
"'" & a & "'"
|
"'" & a & "'"
|
||||||
|
|
||||||
proc genFieldError*(field: PSym, disc: PSym): string =
|
proc genFieldDefect*(field: PSym, disc: PSym): string =
|
||||||
## this needs to be in a module accessible by jsgen, ccgexprs, and vm to
|
## this needs to be in a module accessible by jsgen, ccgexprs, and vm to
|
||||||
## provide this error msg FieldError; msgs would be better but it does not
|
## provide this error msg FieldDefect; msgs would be better but it does not
|
||||||
## import ast
|
## import ast
|
||||||
result = field.name.s.quoteExpr & " is not accessible using discriminant " &
|
result = field.name.s.quoteExpr & " is not accessible using discriminant " &
|
||||||
disc.name.s.quoteExpr & " of type " &
|
disc.name.s.quoteExpr & " of type " &
|
||||||
|
|||||||
@@ -645,9 +645,9 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode =
|
|||||||
discard
|
discard
|
||||||
else:
|
else:
|
||||||
result = magicCall(m, n, g)
|
result = magicCall(m, n, g)
|
||||||
except OverflowError:
|
except OverflowDefect:
|
||||||
localError(g.config, n.info, "over- or underflow")
|
localError(g.config, n.info, "over- or underflow")
|
||||||
except DivByZeroError:
|
except DivByZeroDefect:
|
||||||
localError(g.config, n.info, "division by zero")
|
localError(g.config, n.info, "division by zero")
|
||||||
of nkAddr:
|
of nkAddr:
|
||||||
var a = getConstExpr(m, n[0], g)
|
var a = getConstExpr(m, n[0], g)
|
||||||
|
|||||||
@@ -752,7 +752,7 @@ proc track(tracked: PEffects, n: PNode) =
|
|||||||
createTypeBoundOps(tracked, n[0].typ, n.info)
|
createTypeBoundOps(tracked, n[0].typ, n.info)
|
||||||
else:
|
else:
|
||||||
# A `raise` with no arguments means we're going to re-raise the exception
|
# A `raise` with no arguments means we're going to re-raise the exception
|
||||||
# being handled or, if outside of an `except` block, a `ReraiseError`.
|
# being handled or, if outside of an `except` block, a `ReraiseDefect`.
|
||||||
# Here we add a `Exception` tag in order to cover both the cases.
|
# Here we add a `Exception` tag in order to cover both the cases.
|
||||||
addEffect(tracked, createRaise(tracked.graph, n), nil)
|
addEffect(tracked, createRaise(tracked.graph, n), nil)
|
||||||
of nkCallKinds:
|
of nkCallKinds:
|
||||||
|
|||||||
@@ -451,7 +451,7 @@ Miscellaneous
|
|||||||
This module implements a simple logger.
|
This module implements a simple logger.
|
||||||
|
|
||||||
* `segfaults <segfaults.html>`_
|
* `segfaults <segfaults.html>`_
|
||||||
Turns access violations or segfaults into a ``NilAccessError`` exception.
|
Turns access violations or segfaults into a ``NilAccessDefect`` exception.
|
||||||
|
|
||||||
* `sugar <sugar.html>`_
|
* `sugar <sugar.html>`_
|
||||||
This module implements nice syntactic sugar based on Nim's macro system.
|
This module implements nice syntactic sugar based on Nim's macro system.
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ pragmas_ for details.
|
|||||||
|
|
||||||
Whether a panic results in an exception or in a fatal error is
|
Whether a panic results in an exception or in a fatal error is
|
||||||
implementation specific. Thus the following program is invalid; even though the
|
implementation specific. Thus the following program is invalid; even though the
|
||||||
code purports to catch the `IndexError` from an out-of-bounds array access, the
|
code purports to catch the `IndexDefect` from an out-of-bounds array access, the
|
||||||
compiler may instead choose to allow the program to die with a fatal error.
|
compiler may instead choose to allow the program to die with a fatal error.
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
@@ -121,7 +121,7 @@ compiler may instead choose to allow the program to die with a fatal error.
|
|||||||
let i = 5
|
let i = 5
|
||||||
try:
|
try:
|
||||||
a[i] = 'N'
|
a[i] = 'N'
|
||||||
except IndexError:
|
except IndexDefect:
|
||||||
echo "invalid index"
|
echo "invalid index"
|
||||||
|
|
||||||
The current implementation allows to switch between these different behaviors
|
The current implementation allows to switch between these different behaviors
|
||||||
@@ -1033,10 +1033,10 @@ The IEEE standard defines five types of floating-point exceptions:
|
|||||||
precision, for example, 2.0 / 3.0, log(1.1) and 0.1 in input.
|
precision, for example, 2.0 / 3.0, log(1.1) and 0.1 in input.
|
||||||
|
|
||||||
The IEEE exceptions are either ignored during execution or mapped to the
|
The IEEE exceptions are either ignored during execution or mapped to the
|
||||||
Nim exceptions: `FloatInvalidOpError`:idx:, `FloatDivByZeroError`:idx:,
|
Nim exceptions: `FloatInvalidOpDefect`:idx:, `FloatDivByZeroDefect`:idx:,
|
||||||
`FloatOverflowError`:idx:, `FloatUnderflowError`:idx:,
|
`FloatOverflowDefect`:idx:, `FloatUnderflowDefect`:idx:,
|
||||||
and `FloatInexactError`:idx:.
|
and `FloatInexactDefect`:idx:.
|
||||||
These exceptions inherit from the `FloatingPointError`:idx: base class.
|
These exceptions inherit from the `FloatingPointDefect`:idx: base class.
|
||||||
|
|
||||||
Nim provides the pragmas `nanChecks`:idx: and `infChecks`:idx: to control
|
Nim provides the pragmas `nanChecks`:idx: and `infChecks`:idx: to control
|
||||||
whether the IEEE exceptions are ignored or trap a Nim exception:
|
whether the IEEE exceptions are ignored or trap a Nim exception:
|
||||||
@@ -1045,12 +1045,12 @@ whether the IEEE exceptions are ignored or trap a Nim exception:
|
|||||||
{.nanChecks: on, infChecks: on.}
|
{.nanChecks: on, infChecks: on.}
|
||||||
var a = 1.0
|
var a = 1.0
|
||||||
var b = 0.0
|
var b = 0.0
|
||||||
echo b / b # raises FloatInvalidOpError
|
echo b / b # raises FloatInvalidOpDefect
|
||||||
echo a / b # raises FloatOverflowError
|
echo a / b # raises FloatOverflowDefect
|
||||||
|
|
||||||
In the current implementation ``FloatDivByZeroError`` and ``FloatInexactError``
|
In the current implementation ``FloatDivByZeroDefect`` and ``FloatInexactDefect``
|
||||||
are never raised. ``FloatOverflowError`` is raised instead of
|
are never raised. ``FloatOverflowDefect`` is raised instead of
|
||||||
``FloatDivByZeroError``.
|
``FloatDivByZeroDefect``.
|
||||||
There is also a `floatChecks`:idx: pragma that is a short-cut for the
|
There is also a `floatChecks`:idx: pragma that is a short-cut for the
|
||||||
combination of ``nanChecks`` and ``infChecks`` pragmas. ``floatChecks`` are
|
combination of ``nanChecks`` and ``infChecks`` pragmas. ``floatChecks`` are
|
||||||
turned off as default.
|
turned off as default.
|
||||||
@@ -1620,7 +1620,7 @@ An example:
|
|||||||
# accessing n.thenPart is valid because the ``nkIf`` branch is active:
|
# accessing n.thenPart is valid because the ``nkIf`` branch is active:
|
||||||
n.thenPart = Node(kind: nkFloat, floatVal: 2.0)
|
n.thenPart = Node(kind: nkFloat, floatVal: 2.0)
|
||||||
|
|
||||||
# the following statement raises an `FieldError` exception, because
|
# the following statement raises an `FieldDefect` exception, because
|
||||||
# n.kind's value does not fit and the ``nkString`` branch is not active:
|
# n.kind's value does not fit and the ``nkString`` branch is not active:
|
||||||
n.strVal = ""
|
n.strVal = ""
|
||||||
|
|
||||||
@@ -4063,7 +4063,7 @@ Example:
|
|||||||
var a = readLine(f)
|
var a = readLine(f)
|
||||||
var b = readLine(f)
|
var b = readLine(f)
|
||||||
echo "sum: " & $(parseInt(a) + parseInt(b))
|
echo "sum: " & $(parseInt(a) + parseInt(b))
|
||||||
except OverflowError:
|
except OverflowDefect:
|
||||||
echo "overflow!"
|
echo "overflow!"
|
||||||
except ValueError:
|
except ValueError:
|
||||||
echo "could not convert string to integer"
|
echo "could not convert string to integer"
|
||||||
@@ -4226,7 +4226,7 @@ the ``raise`` statement is the only way to raise an exception.
|
|||||||
.. XXX document this better!
|
.. XXX document this better!
|
||||||
|
|
||||||
If no exception name is given, the current exception is `re-raised`:idx:. The
|
If no exception name is given, the current exception is `re-raised`:idx:. The
|
||||||
`ReraiseError`:idx: exception is raised if there is no exception to
|
`ReraiseDefect`:idx: exception is raised if there is no exception to
|
||||||
re-raise. It follows that the ``raise`` statement *always* raises an
|
re-raise. It follows that the ``raise`` statement *always* raises an
|
||||||
exception.
|
exception.
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ The syntax for type conversions is ``destination_type(expression_to_convert)``
|
|||||||
proc getID(x: Person): int =
|
proc getID(x: Person): int =
|
||||||
Student(x).id
|
Student(x).id
|
||||||
|
|
||||||
The ``InvalidObjectConversionError`` exception is raised if ``x`` is not a
|
The ``InvalidObjectConversionDefect`` exception is raised if ``x`` is not a
|
||||||
``Student``.
|
``Student``.
|
||||||
|
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ An example:
|
|||||||
condition, thenPart, elsePart: Node
|
condition, thenPart, elsePart: Node
|
||||||
|
|
||||||
var n = Node(kind: nkFloat, floatVal: 1.0)
|
var n = Node(kind: nkFloat, floatVal: 1.0)
|
||||||
# the following statement raises an `FieldError` exception, because
|
# the following statement raises an `FieldDefect` exception, because
|
||||||
# n.kind's value does not fit:
|
# n.kind's value does not fit:
|
||||||
n.strVal = ""
|
n.strVal = ""
|
||||||
|
|
||||||
@@ -388,7 +388,7 @@ The ``try`` statement handles exceptions:
|
|||||||
let a = readLine(f)
|
let a = readLine(f)
|
||||||
let b = readLine(f)
|
let b = readLine(f)
|
||||||
echo "sum: ", parseInt(a) + parseInt(b)
|
echo "sum: ", parseInt(a) + parseInt(b)
|
||||||
except OverflowError:
|
except OverflowDefect:
|
||||||
echo "overflow!"
|
echo "overflow!"
|
||||||
except ValueError:
|
except ValueError:
|
||||||
echo "could not convert string to integer"
|
echo "could not convert string to integer"
|
||||||
@@ -443,7 +443,7 @@ instance, if you specify that a proc raises ``IOError``, and at some point it
|
|||||||
prevent that proc from compiling. Usage example:
|
prevent that proc from compiling. Usage example:
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
proc complexProc() {.raises: [IOError, ArithmeticError].} =
|
proc complexProc() {.raises: [IOError, ArithmeticDefect].} =
|
||||||
...
|
...
|
||||||
|
|
||||||
proc simpleProc() {.raises: [].} =
|
proc simpleProc() {.raises: [].} =
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ written.
|
|||||||
|
|
||||||
result = quote do:
|
result = quote do:
|
||||||
if not `arg`:
|
if not `arg`:
|
||||||
raise newException(AssertionError,$`lhs` & `op` & $`rhs`)
|
raise newException(AssertionDefect,$`lhs` & `op` & $`rhs`)
|
||||||
|
|
||||||
let a = 1
|
let a = 1
|
||||||
let b = 2
|
let b = 2
|
||||||
@@ -287,7 +287,7 @@ used to get this output.
|
|||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
if not (a != b):
|
if not (a != b):
|
||||||
raise newException(AssertionError, $a & " != " & $b)
|
raise newException(AssertionDefect, $a & " != " & $b)
|
||||||
|
|
||||||
With Power Comes Responsibility
|
With Power Comes Responsibility
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ proc foo: bool =
|
|||||||
return true
|
return true
|
||||||
|
|
||||||
proc err =
|
proc err =
|
||||||
raise newException(ArithmeticError, "some exception")
|
raise newException(ArithmeticDefect, "some exception")
|
||||||
|
|
||||||
test "final test":
|
test "final test":
|
||||||
echo "inside suite-less test"
|
echo "inside suite-less test"
|
||||||
@@ -40,8 +40,8 @@ test "final test":
|
|||||||
d > 10
|
d > 10
|
||||||
|
|
||||||
test "arithmetic failure":
|
test "arithmetic failure":
|
||||||
expect(ArithmeticError):
|
expect(ArithmeticDefect):
|
||||||
err()
|
err()
|
||||||
|
|
||||||
expect(ArithmeticError, CatchableError):
|
expect(ArithmeticDefect, CatchableError):
|
||||||
discard foo()
|
discard foo()
|
||||||
|
|||||||
@@ -204,14 +204,14 @@ proc `[]`*(x: Any, i: int): Any =
|
|||||||
of tyArray:
|
of tyArray:
|
||||||
var bs = x.rawType.base.size
|
var bs = x.rawType.base.size
|
||||||
if i >=% x.rawType.size div bs:
|
if i >=% x.rawType.size div bs:
|
||||||
raise newException(IndexError, formatErrorIndexBound(i, x.rawType.size div bs))
|
raise newException(IndexDefect, formatErrorIndexBound(i, x.rawType.size div bs))
|
||||||
return newAny(x.value +!! i*bs, x.rawType.base)
|
return newAny(x.value +!! i*bs, x.rawType.base)
|
||||||
of tySequence:
|
of tySequence:
|
||||||
var s = cast[ppointer](x.value)[]
|
var s = cast[ppointer](x.value)[]
|
||||||
if s == nil: raise newException(ValueError, "sequence is nil")
|
if s == nil: raise newException(ValueError, "sequence is nil")
|
||||||
var bs = x.rawType.base.size
|
var bs = x.rawType.base.size
|
||||||
if i >=% cast[PGenSeq](s).len:
|
if i >=% cast[PGenSeq](s).len:
|
||||||
raise newException(IndexError, formatErrorIndexBound(i, cast[PGenSeq](s).len-1))
|
raise newException(IndexDefect, formatErrorIndexBound(i, cast[PGenSeq](s).len-1))
|
||||||
return newAny(s +!! (align(GenericSeqSize, x.rawType.base.align)+i*bs), x.rawType.base)
|
return newAny(s +!! (align(GenericSeqSize, x.rawType.base.align)+i*bs), x.rawType.base)
|
||||||
else: assert false
|
else: assert false
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ proc `[]=`*(x: Any, i: int, y: Any) =
|
|||||||
of tyArray:
|
of tyArray:
|
||||||
var bs = x.rawType.base.size
|
var bs = x.rawType.base.size
|
||||||
if i >=% x.rawType.size div bs:
|
if i >=% x.rawType.size div bs:
|
||||||
raise newException(IndexError, formatErrorIndexBound(i, x.rawType.size div bs))
|
raise newException(IndexDefect, formatErrorIndexBound(i, x.rawType.size div bs))
|
||||||
assert y.rawType == x.rawType.base
|
assert y.rawType == x.rawType.base
|
||||||
genericAssign(x.value +!! i*bs, y.value, y.rawType)
|
genericAssign(x.value +!! i*bs, y.value, y.rawType)
|
||||||
of tySequence:
|
of tySequence:
|
||||||
@@ -229,7 +229,7 @@ proc `[]=`*(x: Any, i: int, y: Any) =
|
|||||||
if s == nil: raise newException(ValueError, "sequence is nil")
|
if s == nil: raise newException(ValueError, "sequence is nil")
|
||||||
var bs = x.rawType.base.size
|
var bs = x.rawType.base.size
|
||||||
if i >=% cast[PGenSeq](s).len:
|
if i >=% cast[PGenSeq](s).len:
|
||||||
raise newException(IndexError, formatErrorIndexBound(i, cast[PGenSeq](s).len-1))
|
raise newException(IndexDefect, formatErrorIndexBound(i, cast[PGenSeq](s).len-1))
|
||||||
assert y.rawType == x.rawType.base
|
assert y.rawType == x.rawType.base
|
||||||
genericAssign(s +!! (align(GenericSeqSize, x.rawType.base.align)+i*bs), y.value, y.rawType)
|
genericAssign(s +!! (align(GenericSeqSize, x.rawType.base.align)+i*bs), y.value, y.rawType)
|
||||||
else: assert false
|
else: assert false
|
||||||
|
|||||||
@@ -49,11 +49,11 @@ proc len*(s: SharedString): int = s.len
|
|||||||
|
|
||||||
proc `[]`*(s: SharedString; i: Natural): char =
|
proc `[]`*(s: SharedString; i: Natural): char =
|
||||||
if i < s.len: result = s.buffer.data[i+s.first]
|
if i < s.len: result = s.buffer.data[i+s.first]
|
||||||
else: raise newException(IndexError, formatErrorIndexBound(i, s.len-1))
|
else: raise newException(IndexDefect, formatErrorIndexBound(i, s.len-1))
|
||||||
|
|
||||||
proc `[]=`*(s: var SharedString; i: Natural; value: char) =
|
proc `[]=`*(s: var SharedString; i: Natural; value: char) =
|
||||||
if i < s.len: s.buffer.data[i+s.first] = value
|
if i < s.len: s.buffer.data[i+s.first] = value
|
||||||
else: raise newException(IndexError, formatErrorIndexBound(i, s.len-1))
|
else: raise newException(IndexDefect, formatErrorIndexBound(i, s.len-1))
|
||||||
|
|
||||||
proc `[]`*(s: SharedString; ab: HSlice[int, int]): SharedString =
|
proc `[]`*(s: SharedString; ab: HSlice[int, int]): SharedString =
|
||||||
#incRef(src.buffer)
|
#incRef(src.buffer)
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ proc getinfo[T](pattern: Regex, opt: cint): T =
|
|||||||
|
|
||||||
if retcode < 0:
|
if retcode < 0:
|
||||||
# XXX Error message that doesn't expose implementation details
|
# XXX Error message that doesn't expose implementation details
|
||||||
raise newException(FieldError, "Invalid getinfo for $1, errno $2" % [$opt, $retcode])
|
raise newException(FieldDefect, "Invalid getinfo for $1, errno $2" % [$opt, $retcode])
|
||||||
|
|
||||||
proc getNameToNumberTable(pattern: Regex): Table[string, int] =
|
proc getNameToNumberTable(pattern: Regex): Table[string, int] =
|
||||||
let entryCount = getinfo[cint](pattern, pcre.INFO_NAMECOUNT)
|
let entryCount = getinfo[cint](pattern, pcre.INFO_NAMECOUNT)
|
||||||
@@ -331,7 +331,7 @@ func contains*(pattern: Captures, i: int): bool =
|
|||||||
func `[]`*(pattern: CaptureBounds, i: int): HSlice[int, int] =
|
func `[]`*(pattern: CaptureBounds, i: int): HSlice[int, int] =
|
||||||
let pattern = RegexMatch(pattern)
|
let pattern = RegexMatch(pattern)
|
||||||
if not (i in pattern.captureBounds):
|
if not (i in pattern.captureBounds):
|
||||||
raise newException(IndexError, "Group '" & $i & "' was not captured")
|
raise newException(IndexDefect, "Group '" & $i & "' was not captured")
|
||||||
|
|
||||||
let bounds = pattern.pcreMatchBounds[i + 1]
|
let bounds = pattern.pcreMatchBounds[i + 1]
|
||||||
int(bounds.a)..int(bounds.b-1)
|
int(bounds.a)..int(bounds.b-1)
|
||||||
@@ -517,7 +517,7 @@ proc matchImpl(str: string, pattern: Regex, start, endpos: int, flags: int): Opt
|
|||||||
of pcre.ERROR_NOMATCH:
|
of pcre.ERROR_NOMATCH:
|
||||||
return none(RegexMatch)
|
return none(RegexMatch)
|
||||||
of pcre.ERROR_NULL:
|
of pcre.ERROR_NULL:
|
||||||
raise newException(AccessViolationError, "Expected non-null parameters")
|
raise newException(AccessViolationDefect, "Expected non-null parameters")
|
||||||
of pcre.ERROR_BADOPTION:
|
of pcre.ERROR_BADOPTION:
|
||||||
raise RegexInternalError(msg : "Unknown pattern flag. Either a bug or " &
|
raise RegexInternalError(msg : "Unknown pattern flag. Either a bug or " &
|
||||||
"outdated PCRE.")
|
"outdated PCRE.")
|
||||||
@@ -718,7 +718,7 @@ proc replace*(str: string, pattern: Regex,
|
|||||||
## - ``$#`` - first capture
|
## - ``$#`` - first capture
|
||||||
## - ``$0`` - full match
|
## - ``$0`` - full match
|
||||||
##
|
##
|
||||||
## If a given capture is missing, ``IndexError`` thrown for un-named captures
|
## If a given capture is missing, ``IndexDefect`` thrown for un-named captures
|
||||||
## and ``KeyError`` for named captures.
|
## and ``KeyError`` for named captures.
|
||||||
replaceImpl(str, pattern, subproc(match))
|
replaceImpl(str, pattern, subproc(match))
|
||||||
|
|
||||||
|
|||||||
@@ -75,14 +75,14 @@ template fillImpl[T](a: var openArray[T], first, last: int, value: T) =
|
|||||||
proc fill*[T](a: var openArray[T], first, last: Natural, value: T) =
|
proc fill*[T](a: var openArray[T], first, last: Natural, value: T) =
|
||||||
## Fills the slice ``a[first..last]`` with ``value``.
|
## Fills the slice ``a[first..last]`` with ``value``.
|
||||||
##
|
##
|
||||||
## If an invalid range is passed, it raises IndexError.
|
## If an invalid range is passed, it raises IndexDefect.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var a: array[6, int]
|
var a: array[6, int]
|
||||||
a.fill(1, 3, 9)
|
a.fill(1, 3, 9)
|
||||||
assert a == [0, 9, 9, 9, 0, 0]
|
assert a == [0, 9, 9, 9, 0, 0]
|
||||||
a.fill(3, 5, 7)
|
a.fill(3, 5, 7)
|
||||||
assert a == [0, 9, 9, 7, 7, 7]
|
assert a == [0, 9, 9, 7, 7, 7]
|
||||||
doAssertRaises(IndexError, a.fill(1, 7, 9))
|
doAssertRaises(IndexDefect, a.fill(1, 7, 9))
|
||||||
fillImpl(a, first, last, value)
|
fillImpl(a, first, last, value)
|
||||||
|
|
||||||
proc fill*[T](a: var openArray[T], value: T) =
|
proc fill*[T](a: var openArray[T], value: T) =
|
||||||
@@ -99,7 +99,7 @@ proc fill*[T](a: var openArray[T], value: T) =
|
|||||||
proc reverse*[T](a: var openArray[T], first, last: Natural) =
|
proc reverse*[T](a: var openArray[T], first, last: Natural) =
|
||||||
## Reverses the slice ``a[first..last]``.
|
## Reverses the slice ``a[first..last]``.
|
||||||
##
|
##
|
||||||
## If an invalid range is passed, it raises IndexError.
|
## If an invalid range is passed, it raises IndexDefect.
|
||||||
##
|
##
|
||||||
## **See also:**
|
## **See also:**
|
||||||
## * `reversed proc<#reversed,openArray[T],Natural,int>`_ reverse a slice and returns a ``seq[T]``
|
## * `reversed proc<#reversed,openArray[T],Natural,int>`_ reverse a slice and returns a ``seq[T]``
|
||||||
@@ -110,7 +110,7 @@ proc reverse*[T](a: var openArray[T], first, last: Natural) =
|
|||||||
assert a == [1, 4, 3, 2, 5, 6]
|
assert a == [1, 4, 3, 2, 5, 6]
|
||||||
a.reverse(1, 3)
|
a.reverse(1, 3)
|
||||||
assert a == [1, 2, 3, 4, 5, 6]
|
assert a == [1, 2, 3, 4, 5, 6]
|
||||||
doAssertRaises(IndexError, a.reverse(1, 7))
|
doAssertRaises(IndexDefect, a.reverse(1, 7))
|
||||||
var x = first
|
var x = first
|
||||||
var y = last
|
var y = last
|
||||||
while x < y:
|
while x < y:
|
||||||
@@ -135,7 +135,7 @@ proc reverse*[T](a: var openArray[T]) =
|
|||||||
proc reversed*[T](a: openArray[T], first: Natural, last: int): seq[T] =
|
proc reversed*[T](a: openArray[T], first: Natural, last: int): seq[T] =
|
||||||
## Returns the reverse of the slice ``a[first..last]``.
|
## Returns the reverse of the slice ``a[first..last]``.
|
||||||
##
|
##
|
||||||
## If an invalid range is passed, it raises IndexError.
|
## If an invalid range is passed, it raises IndexDefect.
|
||||||
##
|
##
|
||||||
## **See also:**
|
## **See also:**
|
||||||
## * `reverse proc<#reverse,openArray[T],Natural,Natural>`_ reverse a slice
|
## * `reverse proc<#reverse,openArray[T],Natural,Natural>`_ reverse a slice
|
||||||
@@ -238,7 +238,7 @@ proc lowerBound*[T, K](a: openArray[T], key: K, cmp: proc(x: T, k: K): int {.
|
|||||||
## ``insert(thing, elm, lowerBound(thing, elm))``
|
## ``insert(thing, elm, lowerBound(thing, elm))``
|
||||||
## the sequence will still be sorted.
|
## the sequence will still be sorted.
|
||||||
##
|
##
|
||||||
## If an invalid range is passed, it raises IndexError.
|
## If an invalid range is passed, it raises IndexDefect.
|
||||||
##
|
##
|
||||||
## The version uses ``cmp`` to compare the elements.
|
## The version uses ``cmp`` to compare the elements.
|
||||||
## The expected return values are the same as that of ``system.cmp``.
|
## The expected return values are the same as that of ``system.cmp``.
|
||||||
@@ -286,7 +286,7 @@ proc upperBound*[T, K](a: openArray[T], key: K, cmp: proc(x: T, k: K): int {.
|
|||||||
## ``insert(thing, elm, upperBound(thing, elm))``
|
## ``insert(thing, elm, upperBound(thing, elm))``
|
||||||
## the sequence will still be sorted.
|
## the sequence will still be sorted.
|
||||||
##
|
##
|
||||||
## If an invalid range is passed, it raises IndexError.
|
## If an invalid range is passed, it raises IndexDefect.
|
||||||
##
|
##
|
||||||
## The version uses ``cmp`` to compare the elements. The expected
|
## The version uses ``cmp`` to compare the elements. The expected
|
||||||
## return values are the same as that of ``system.cmp``.
|
## return values are the same as that of ``system.cmp``.
|
||||||
@@ -763,7 +763,7 @@ proc rotateLeft*[T](arg: var openArray[T]; slice: HSlice[int, int];
|
|||||||
##
|
##
|
||||||
## Elements outside of ``slice`` will be left unchanged.
|
## Elements outside of ``slice`` will be left unchanged.
|
||||||
## The time complexity is linear to ``slice.b - slice.a + 1``.
|
## The time complexity is linear to ``slice.b - slice.a + 1``.
|
||||||
## If an invalid range (``HSlice``) is passed, it raises IndexError.
|
## If an invalid range (``HSlice``) is passed, it raises IndexDefect.
|
||||||
##
|
##
|
||||||
## ``slice``
|
## ``slice``
|
||||||
## The indices of the element range that should be rotated.
|
## The indices of the element range that should be rotated.
|
||||||
@@ -783,7 +783,7 @@ proc rotateLeft*[T](arg: var openArray[T]; slice: HSlice[int, int];
|
|||||||
assert a == [0, 3, 4, 1, 2, 5]
|
assert a == [0, 3, 4, 1, 2, 5]
|
||||||
a.rotateLeft(1 .. 4, -3)
|
a.rotateLeft(1 .. 4, -3)
|
||||||
assert a == [0, 4, 1, 2, 3, 5]
|
assert a == [0, 4, 1, 2, 3, 5]
|
||||||
doAssertRaises(IndexError, a.rotateLeft(1 .. 7, 2))
|
doAssertRaises(IndexDefect, a.rotateLeft(1 .. 7, 2))
|
||||||
let sliceLen = slice.b + 1 - slice.a
|
let sliceLen = slice.b + 1 - slice.a
|
||||||
let distLeft = ((dist mod sliceLen) + sliceLen) mod sliceLen
|
let distLeft = ((dist mod sliceLen) + sliceLen) mod sliceLen
|
||||||
arg.rotateInternal(slice.a, slice.a+distLeft, slice.b + 1)
|
arg.rotateInternal(slice.a, slice.a+distLeft, slice.b + 1)
|
||||||
@@ -813,7 +813,7 @@ proc rotatedLeft*[T](arg: openArray[T]; slice: HSlice[int, int],
|
|||||||
## not modify the argument. It creates a new ``seq`` instead.
|
## not modify the argument. It creates a new ``seq`` instead.
|
||||||
##
|
##
|
||||||
## Elements outside of ``slice`` will be left unchanged.
|
## Elements outside of ``slice`` will be left unchanged.
|
||||||
## If an invalid range (``HSlice``) is passed, it raises IndexError.
|
## If an invalid range (``HSlice``) is passed, it raises IndexDefect.
|
||||||
##
|
##
|
||||||
## ``slice``
|
## ``slice``
|
||||||
## The indices of the element range that should be rotated.
|
## The indices of the element range that should be rotated.
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ template createCb(retFutureSym, iteratorNameSym,
|
|||||||
if not retFutUnown.finished:
|
if not retFutUnown.finished:
|
||||||
let msg = "Async procedure ($1) yielded `nil`, are you await'ing a " &
|
let msg = "Async procedure ($1) yielded `nil`, are you await'ing a " &
|
||||||
"`nil` Future?"
|
"`nil` Future?"
|
||||||
raise newException(AssertionError, msg % strName)
|
raise newException(AssertionDefect, msg % strName)
|
||||||
else:
|
else:
|
||||||
{.gcsafe.}:
|
{.gcsafe.}:
|
||||||
{.push hint[ConvFromXtoItselfNotNeeded]: off.}
|
{.push hint[ConvFromXtoItselfNotNeeded]: off.}
|
||||||
@@ -260,7 +260,7 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
|||||||
template await(f: typed): untyped =
|
template await(f: typed): untyped =
|
||||||
static:
|
static:
|
||||||
error "await expects Future[T], got " & $typeof(f)
|
error "await expects Future[T], got " & $typeof(f)
|
||||||
|
|
||||||
template await[T](f: Future[T]): auto =
|
template await[T](f: Future[T]): auto =
|
||||||
var internalTmpFuture: FutureBase = f
|
var internalTmpFuture: FutureBase = f
|
||||||
yield internalTmpFuture
|
yield internalTmpFuture
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
##
|
##
|
||||||
## None of the procs that get an individual value from the deque can be used
|
## None of the procs that get an individual value from the deque can be used
|
||||||
## on an empty deque.
|
## on an empty deque.
|
||||||
## If compiled with `boundChecks` option, those procs will raise an `IndexError`
|
## If compiled with `boundChecks` option, those procs will raise an `IndexDefect`
|
||||||
## on such access. This should not be relied upon, as `-d:release` will
|
## on such access. This should not be relied upon, as `-d:release` will
|
||||||
## disable those checks and may return garbage or crash the program.
|
## disable those checks and may return garbage or crash the program.
|
||||||
##
|
##
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
##
|
##
|
||||||
## var a = initDeque[int]()
|
## var a = initDeque[int]()
|
||||||
##
|
##
|
||||||
## doAssertRaises(IndexError, echo a[0])
|
## doAssertRaises(IndexDefect, echo a[0])
|
||||||
##
|
##
|
||||||
## for i in 1 .. 5:
|
## for i in 1 .. 5:
|
||||||
## a.addLast(10*i)
|
## a.addLast(10*i)
|
||||||
@@ -70,7 +70,7 @@ template initImpl(result: typed, initialSize: int) =
|
|||||||
assert isPowerOfTwo(initialSize)
|
assert isPowerOfTwo(initialSize)
|
||||||
result.mask = initialSize-1
|
result.mask = initialSize-1
|
||||||
newSeq(result.data, initialSize)
|
newSeq(result.data, initialSize)
|
||||||
|
|
||||||
template checkIfInitialized(deq: typed) =
|
template checkIfInitialized(deq: typed) =
|
||||||
when compiles(defaultInitialSize):
|
when compiles(defaultInitialSize):
|
||||||
if deq.mask == 0:
|
if deq.mask == 0:
|
||||||
@@ -97,16 +97,16 @@ template emptyCheck(deq) =
|
|||||||
# Bounds check for the regular deque access.
|
# Bounds check for the regular deque access.
|
||||||
when compileOption("boundChecks"):
|
when compileOption("boundChecks"):
|
||||||
if unlikely(deq.count < 1):
|
if unlikely(deq.count < 1):
|
||||||
raise newException(IndexError, "Empty deque.")
|
raise newException(IndexDefect, "Empty deque.")
|
||||||
|
|
||||||
template xBoundsCheck(deq, i) =
|
template xBoundsCheck(deq, i) =
|
||||||
# Bounds check for the array like accesses.
|
# Bounds check for the array like accesses.
|
||||||
when compileOption("boundChecks"): # d:release should disable this.
|
when compileOption("boundChecks"): # d:release should disable this.
|
||||||
if unlikely(i >= deq.count): # x < deq.low is taken care by the Natural parameter
|
if unlikely(i >= deq.count): # x < deq.low is taken care by the Natural parameter
|
||||||
raise newException(IndexError,
|
raise newException(IndexDefect,
|
||||||
"Out of bounds: " & $i & " > " & $(deq.count - 1))
|
"Out of bounds: " & $i & " > " & $(deq.count - 1))
|
||||||
if unlikely(i < 0): # when used with BackwardsIndex
|
if unlikely(i < 0): # when used with BackwardsIndex
|
||||||
raise newException(IndexError,
|
raise newException(IndexDefect,
|
||||||
"Out of bounds: " & $i & " < 0")
|
"Out of bounds: " & $i & " < 0")
|
||||||
|
|
||||||
proc `[]`*[T](deq: Deque[T], i: Natural): T {.inline.} =
|
proc `[]`*[T](deq: Deque[T], i: Natural): T {.inline.} =
|
||||||
@@ -117,7 +117,7 @@ proc `[]`*[T](deq: Deque[T], i: Natural): T {.inline.} =
|
|||||||
a.addLast(10*i)
|
a.addLast(10*i)
|
||||||
assert a[0] == 10
|
assert a[0] == 10
|
||||||
assert a[3] == 40
|
assert a[3] == 40
|
||||||
doAssertRaises(IndexError, echo a[8])
|
doAssertRaises(IndexDefect, echo a[8])
|
||||||
|
|
||||||
xBoundsCheck(deq, i)
|
xBoundsCheck(deq, i)
|
||||||
return deq.data[(deq.head + i) and deq.mask]
|
return deq.data[(deq.head + i) and deq.mask]
|
||||||
@@ -131,7 +131,7 @@ proc `[]`*[T](deq: var Deque[T], i: Natural): var T {.inline.} =
|
|||||||
a.addLast(10*i)
|
a.addLast(10*i)
|
||||||
assert a[0] == 10
|
assert a[0] == 10
|
||||||
assert a[3] == 40
|
assert a[3] == 40
|
||||||
doAssertRaises(IndexError, echo a[8])
|
doAssertRaises(IndexDefect, echo a[8])
|
||||||
|
|
||||||
xBoundsCheck(deq, i)
|
xBoundsCheck(deq, i)
|
||||||
return deq.data[(deq.head + i) and deq.mask]
|
return deq.data[(deq.head + i) and deq.mask]
|
||||||
@@ -160,7 +160,7 @@ proc `[]`*[T](deq: Deque[T], i: BackwardsIndex): T {.inline.} =
|
|||||||
a.addLast(10*i)
|
a.addLast(10*i)
|
||||||
assert a[^1] == 50
|
assert a[^1] == 50
|
||||||
assert a[^4] == 20
|
assert a[^4] == 20
|
||||||
doAssertRaises(IndexError, echo a[^9])
|
doAssertRaises(IndexDefect, echo a[^9])
|
||||||
|
|
||||||
xBoundsCheck(deq, deq.len - int(i))
|
xBoundsCheck(deq, deq.len - int(i))
|
||||||
return deq[deq.len - int(i)]
|
return deq[deq.len - int(i)]
|
||||||
@@ -175,7 +175,7 @@ proc `[]`*[T](deq: var Deque[T], i: BackwardsIndex): var T {.inline.} =
|
|||||||
a.addLast(10*i)
|
a.addLast(10*i)
|
||||||
assert a[^1] == 50
|
assert a[^1] == 50
|
||||||
assert a[^4] == 20
|
assert a[^4] == 20
|
||||||
doAssertRaises(IndexError, echo a[^9])
|
doAssertRaises(IndexDefect, echo a[^9])
|
||||||
|
|
||||||
xBoundsCheck(deq, deq.len - int(i))
|
xBoundsCheck(deq, deq.len - int(i))
|
||||||
return deq[deq.len - int(i)]
|
return deq[deq.len - int(i)]
|
||||||
@@ -569,14 +569,14 @@ when isMainModule:
|
|||||||
try:
|
try:
|
||||||
echo deq[99]
|
echo deq[99]
|
||||||
assert false
|
assert false
|
||||||
except IndexError:
|
except IndexDefect:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
try:
|
try:
|
||||||
assert deq.len == 4
|
assert deq.len == 4
|
||||||
for i in 0 ..< 5: deq.popFirst()
|
for i in 0 ..< 5: deq.popFirst()
|
||||||
assert false
|
assert false
|
||||||
except IndexError:
|
except IndexDefect:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
# grabs some types of resize error.
|
# grabs some types of resize error.
|
||||||
|
|||||||
@@ -26,11 +26,11 @@
|
|||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## import asyncdispatch, httpclient
|
## import asyncdispatch, httpclient
|
||||||
##
|
##
|
||||||
## proc asyncProc(): Future[string] {.async.} =
|
## proc asyncProc(): Future[string] {.async.} =
|
||||||
## var client = newAsyncHttpClient()
|
## var client = newAsyncHttpClient()
|
||||||
## return await client.getContent("http://example.com")
|
## return await client.getContent("http://example.com")
|
||||||
##
|
##
|
||||||
## echo waitFor asyncProc()
|
## echo waitFor asyncProc()
|
||||||
##
|
##
|
||||||
## The functionality implemented by ``HttpClient`` and ``AsyncHttpClient``
|
## The functionality implemented by ``HttpClient`` and ``AsyncHttpClient``
|
||||||
@@ -225,7 +225,7 @@ type
|
|||||||
bodyStream*: FutureStream[string]
|
bodyStream*: FutureStream[string]
|
||||||
|
|
||||||
proc code*(response: Response | AsyncResponse): HttpCode
|
proc code*(response: Response | AsyncResponse): HttpCode
|
||||||
{.raises: [ValueError, OverflowError].} =
|
{.raises: [ValueError, OverflowDefect].} =
|
||||||
## Retrieves the specified response's ``HttpCode``.
|
## Retrieves the specified response's ``HttpCode``.
|
||||||
##
|
##
|
||||||
## Raises a ``ValueError`` if the response's ``status`` does not have a
|
## Raises a ``ValueError`` if the response's ``status`` does not have a
|
||||||
|
|||||||
@@ -1300,18 +1300,18 @@ when isMainModule:
|
|||||||
when compileOption("boundChecks"):
|
when compileOption("boundChecks"):
|
||||||
try:
|
try:
|
||||||
let a = testJson["a"][9]
|
let a = testJson["a"][9]
|
||||||
doAssert(false, "IndexError not thrown")
|
doAssert(false, "IndexDefect not thrown")
|
||||||
except IndexError:
|
except IndexDefect:
|
||||||
discard
|
discard
|
||||||
try:
|
try:
|
||||||
let a = testJson["a"][-1]
|
let a = testJson["a"][-1]
|
||||||
doAssert(false, "IndexError not thrown")
|
doAssert(false, "IndexDefect not thrown")
|
||||||
except IndexError:
|
except IndexDefect:
|
||||||
discard
|
discard
|
||||||
try:
|
try:
|
||||||
doAssert(testJson["a"][0].num == 1, "Index doesn't correspond to its value")
|
doAssert(testJson["a"][0].num == 1, "Index doesn't correspond to its value")
|
||||||
except:
|
except:
|
||||||
doAssert(false, "IndexError thrown for valid index")
|
doAssert(false, "IndexDefect thrown for valid index")
|
||||||
|
|
||||||
doAssert(testJson{"b"}.getStr() == "asd", "Couldn't fetch a singly nested key with {}")
|
doAssert(testJson{"b"}.getStr() == "asd", "Couldn't fetch a singly nested key with {}")
|
||||||
doAssert(isNil(testJson{"nonexistent"}), "Non-existent keys should return nil")
|
doAssert(isNil(testJson{"nonexistent"}), "Non-existent keys should return nil")
|
||||||
@@ -1378,7 +1378,7 @@ when isMainModule:
|
|||||||
try:
|
try:
|
||||||
discard parsed["key2"][12123]
|
discard parsed["key2"][12123]
|
||||||
doAssert(false)
|
doAssert(false)
|
||||||
except IndexError: doAssert(true)
|
except IndexDefect: doAssert(true)
|
||||||
|
|
||||||
var parsed2 = parseFile("tests/testdata/jsontest2.json")
|
var parsed2 = parseFile("tests/testdata/jsontest2.json")
|
||||||
doAssert(parsed2{"repository", "description"}.str ==
|
doAssert(parsed2{"repository", "description"}.str ==
|
||||||
|
|||||||
@@ -1205,7 +1205,7 @@ when isMainModule:
|
|||||||
block: # fac() tests
|
block: # fac() tests
|
||||||
try:
|
try:
|
||||||
discard fac(-1)
|
discard fac(-1)
|
||||||
except AssertionError:
|
except AssertionDefect:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
doAssert fac(0) == 1
|
doAssert fac(0) == 1
|
||||||
|
|||||||
@@ -457,7 +457,7 @@ proc fromSockAddrAux(sa: ptr Sockaddr_storage, sl: SockLen,
|
|||||||
proc fromSockAddr*(sa: Sockaddr_storage | SockAddr | Sockaddr_in | Sockaddr_in6,
|
proc fromSockAddr*(sa: Sockaddr_storage | SockAddr | Sockaddr_in | Sockaddr_in6,
|
||||||
sl: SockLen, address: var IpAddress, port: var Port) {.inline.} =
|
sl: SockLen, address: var IpAddress, port: var Port) {.inline.} =
|
||||||
## Converts `SockAddr` and `SockLen` to `IpAddress` and `Port`. Raises
|
## Converts `SockAddr` and `SockLen` to `IpAddress` and `Port`. Raises
|
||||||
## `ObjectConversionError` in case of invalid `sa` and `sl` arguments.
|
## `ObjectConversionDefect` in case of invalid `sa` and `sl` arguments.
|
||||||
fromSockAddrAux(cast[ptr Sockaddr_storage](unsafeAddr sa), sl, address, port)
|
fromSockAddrAux(cast[ptr Sockaddr_storage](unsafeAddr sa), sl, address, port)
|
||||||
|
|
||||||
when defineSsl:
|
when defineSsl:
|
||||||
@@ -488,7 +488,7 @@ when defineSsl:
|
|||||||
proc getExtraData*(ctx: SslContext, index: int): RootRef =
|
proc getExtraData*(ctx: SslContext, index: int): RootRef =
|
||||||
## Retrieves arbitrary data stored inside SslContext.
|
## Retrieves arbitrary data stored inside SslContext.
|
||||||
if index notin ctx.referencedData:
|
if index notin ctx.referencedData:
|
||||||
raise newException(IndexError, "No data with that index.")
|
raise newException(IndexDefect, "No data with that index.")
|
||||||
let res = ctx.context.SSL_CTX_get_ex_data(index.cint)
|
let res = ctx.context.SSL_CTX_get_ex_data(index.cint)
|
||||||
if cast[int](res) == 0:
|
if cast[int](res) == 0:
|
||||||
raiseSSLError()
|
raiseSSLError()
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ type
|
|||||||
val: T
|
val: T
|
||||||
has: bool
|
has: bool
|
||||||
|
|
||||||
UnpackError* = object of Defect
|
UnpackDefect* = object of Defect
|
||||||
|
UnpackError* {.deprecated: "See corresponding Defect".} = UnpackDefect
|
||||||
|
|
||||||
proc option*[T](val: T): Option[T] =
|
proc option*[T](val: T): Option[T] =
|
||||||
## Can be used to convert a pointer type (`ptr` or `ref` or `proc`) to an option type.
|
## Can be used to convert a pointer type (`ptr` or `ref` or `proc`) to an option type.
|
||||||
@@ -486,7 +486,7 @@ when isMainModule:
|
|||||||
|
|
||||||
let tmp = option(intref)
|
let tmp = option(intref)
|
||||||
check(sizeof(tmp) == sizeof(ptr int))
|
check(sizeof(tmp) == sizeof(ptr int))
|
||||||
|
|
||||||
var prc = proc (x: int): int = x + 1
|
var prc = proc (x: int): int = x + 1
|
||||||
check(option(prc).isSome)
|
check(option(prc).isSome)
|
||||||
prc = nil
|
prc = nil
|
||||||
|
|||||||
@@ -2678,7 +2678,7 @@ when defined(nimdoc):
|
|||||||
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
|
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
|
||||||
## Returns the `i`-th `command line argument`:idx: given to the application.
|
## Returns the `i`-th `command line argument`:idx: given to the application.
|
||||||
##
|
##
|
||||||
## `i` should be in the range `1..paramCount()`, the `IndexError`
|
## `i` should be in the range `1..paramCount()`, the `IndexDefect`
|
||||||
## exception will be raised for invalid values. Instead of iterating over
|
## exception will be raised for invalid values. Instead of iterating over
|
||||||
## `paramCount() <#paramCount>`_ with this proc you can call the
|
## `paramCount() <#paramCount>`_ with this proc you can call the
|
||||||
## convenience `commandLineParams() <#commandLineParams>`_.
|
## convenience `commandLineParams() <#commandLineParams>`_.
|
||||||
@@ -2754,7 +2754,7 @@ elif defined(windows):
|
|||||||
ownArgv = parseCmdLine($getCommandLine())
|
ownArgv = parseCmdLine($getCommandLine())
|
||||||
ownParsedArgv = true
|
ownParsedArgv = true
|
||||||
if i < ownArgv.len and i >= 0: return TaintedString(ownArgv[i])
|
if i < ownArgv.len and i >= 0: return TaintedString(ownArgv[i])
|
||||||
raise newException(IndexError, formatErrorIndexBound(i, ownArgv.len-1))
|
raise newException(IndexDefect, formatErrorIndexBound(i, ownArgv.len-1))
|
||||||
|
|
||||||
elif defined(genode):
|
elif defined(genode):
|
||||||
proc paramStr*(i: int): TaintedString =
|
proc paramStr*(i: int): TaintedString =
|
||||||
@@ -2773,7 +2773,7 @@ elif not defined(createNimRtl) and
|
|||||||
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
|
proc paramStr*(i: int): TaintedString {.tags: [ReadIOEffect].} =
|
||||||
# Docstring in nimdoc block.
|
# Docstring in nimdoc block.
|
||||||
if i < cmdCount and i >= 0: return TaintedString($cmdLine[i])
|
if i < cmdCount and i >= 0: return TaintedString($cmdLine[i])
|
||||||
raise newException(IndexError, formatErrorIndexBound(i, cmdCount-1))
|
raise newException(IndexDefect, formatErrorIndexBound(i, cmdCount-1))
|
||||||
|
|
||||||
proc paramCount*(): int {.tags: [ReadIOEffect].} =
|
proc paramCount*(): int {.tags: [ReadIOEffect].} =
|
||||||
# Docstring in nimdoc block.
|
# Docstring in nimdoc block.
|
||||||
|
|||||||
@@ -393,7 +393,7 @@ proc captureBetween*(s: string, first: char, second = '\0', start = 0): string =
|
|||||||
result = ""
|
result = ""
|
||||||
discard s.parseUntil(result, if second == '\0': first else: second, i)
|
discard s.parseUntil(result, if second == '\0': first else: second, i)
|
||||||
|
|
||||||
proc integerOutOfRangeError() {.noinline.} =
|
proc integerOutOfRangeDefect() {.noinline.} =
|
||||||
raise newException(ValueError, "Parsed integer outside of valid range")
|
raise newException(ValueError, "Parsed integer outside of valid range")
|
||||||
|
|
||||||
# See #6752
|
# See #6752
|
||||||
@@ -416,11 +416,11 @@ proc rawParseInt(s: string, b: var BiggestInt, start = 0): int =
|
|||||||
if b >= (low(BiggestInt) + c) div 10:
|
if b >= (low(BiggestInt) + c) div 10:
|
||||||
b = b * 10 - c
|
b = b * 10 - c
|
||||||
else:
|
else:
|
||||||
integerOutOfRangeError()
|
integerOutOfRangeDefect()
|
||||||
inc(i)
|
inc(i)
|
||||||
while i < s.len and s[i] == '_': inc(i) # underscores are allowed and ignored
|
while i < s.len and s[i] == '_': inc(i) # underscores are allowed and ignored
|
||||||
if sign == -1 and b == low(BiggestInt):
|
if sign == -1 and b == low(BiggestInt):
|
||||||
integerOutOfRangeError()
|
integerOutOfRangeDefect()
|
||||||
else:
|
else:
|
||||||
b = b * sign
|
b = b * sign
|
||||||
result = i - start
|
result = i - start
|
||||||
@@ -459,7 +459,7 @@ proc parseInt*(s: string, number: var int, start = 0): int {.
|
|||||||
result = parseBiggestInt(s, res, start)
|
result = parseBiggestInt(s, res, start)
|
||||||
when sizeof(int) <= 4:
|
when sizeof(int) <= 4:
|
||||||
if res < low(int) or res > high(int):
|
if res < low(int) or res > high(int):
|
||||||
integerOutOfRangeError()
|
integerOutOfRangeDefect()
|
||||||
if result != 0:
|
if result != 0:
|
||||||
number = int(res)
|
number = int(res)
|
||||||
|
|
||||||
@@ -493,7 +493,7 @@ proc rawParseUInt(s: string, b: var BiggestUInt, start = 0): int =
|
|||||||
prev = 0.BiggestUInt
|
prev = 0.BiggestUInt
|
||||||
i = start
|
i = start
|
||||||
if i < s.len - 1 and s[i] == '-' and s[i + 1] in {'0'..'9'}:
|
if i < s.len - 1 and s[i] == '-' and s[i + 1] in {'0'..'9'}:
|
||||||
integerOutOfRangeError()
|
integerOutOfRangeDefect()
|
||||||
if i < s.len and s[i] == '+': inc(i) # Allow
|
if i < s.len and s[i] == '+': inc(i) # Allow
|
||||||
if i < s.len and s[i] in {'0'..'9'}:
|
if i < s.len and s[i] in {'0'..'9'}:
|
||||||
b = 0
|
b = 0
|
||||||
@@ -501,7 +501,7 @@ proc rawParseUInt(s: string, b: var BiggestUInt, start = 0): int =
|
|||||||
prev = res
|
prev = res
|
||||||
res = res * 10 + (ord(s[i]) - ord('0')).BiggestUInt
|
res = res * 10 + (ord(s[i]) - ord('0')).BiggestUInt
|
||||||
if prev > res:
|
if prev > res:
|
||||||
integerOutOfRangeError()
|
integerOutOfRangeDefect()
|
||||||
inc(i)
|
inc(i)
|
||||||
while i < s.len and s[i] == '_': inc(i) # underscores are allowed and ignored
|
while i < s.len and s[i] == '_': inc(i) # underscores are allowed and ignored
|
||||||
b = res
|
b = res
|
||||||
@@ -540,7 +540,7 @@ proc parseUInt*(s: string, number: var uint, start = 0): int {.
|
|||||||
result = parseBiggestUInt(s, res, start)
|
result = parseBiggestUInt(s, res, start)
|
||||||
when sizeof(BiggestUInt) > sizeof(uint) and sizeof(uint) <= 4:
|
when sizeof(BiggestUInt) > sizeof(uint) and sizeof(uint) <= 4:
|
||||||
if res > 0xFFFF_FFFF'u64:
|
if res > 0xFFFF_FFFF'u64:
|
||||||
integerOutOfRangeError()
|
integerOutOfRangeDefect()
|
||||||
if result != 0:
|
if result != 0:
|
||||||
number = uint(res)
|
number = uint(res)
|
||||||
|
|
||||||
|
|||||||
@@ -676,13 +676,13 @@ when isMainModule:
|
|||||||
try:
|
try:
|
||||||
discard rand(-1)
|
discard rand(-1)
|
||||||
doAssert false
|
doAssert false
|
||||||
except RangeError:
|
except RangeDefect:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
try:
|
try:
|
||||||
discard rand(-1.0)
|
discard rand(-1.0)
|
||||||
doAssert false
|
doAssert false
|
||||||
except RangeError:
|
except RangeDefect:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ proc reduce*[T: SomeInteger](x: var Rational[T]) =
|
|||||||
x.num = -x.num div common
|
x.num = -x.num div common
|
||||||
x.den = -x.den div common
|
x.den = -x.den div common
|
||||||
else:
|
else:
|
||||||
raise newException(DivByZeroError, "division by zero")
|
raise newException(DivByZeroDefect, "division by zero")
|
||||||
|
|
||||||
proc `+` *[T](x, y: Rational[T]): Rational[T] =
|
proc `+` *[T](x, y: Rational[T]): Rational[T] =
|
||||||
## Add two rational numbers.
|
## Add two rational numbers.
|
||||||
@@ -194,7 +194,7 @@ proc reciprocal*[T](x: Rational[T]): Rational[T] =
|
|||||||
result.num = -x.den
|
result.num = -x.den
|
||||||
result.den = -x.num
|
result.den = -x.num
|
||||||
else:
|
else:
|
||||||
raise newException(DivByZeroError, "division by zero")
|
raise newException(DivByZeroDefect, "division by zero")
|
||||||
|
|
||||||
proc `/`*[T](x, y: Rational[T]): Rational[T] =
|
proc `/`*[T](x, y: Rational[T]): Rational[T] =
|
||||||
## Divide rationals `x` by `y`.
|
## Divide rationals `x` by `y`.
|
||||||
|
|||||||
@@ -8,17 +8,17 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
## This modules registers a signal handler that turns access violations /
|
## This modules registers a signal handler that turns access violations /
|
||||||
## segfaults into a ``NilAccessError`` exception. To be able to catch
|
## segfaults into a ``NilAccessDefect`` exception. To be able to catch
|
||||||
## a NilAccessError all you have to do is to import this module.
|
## a NilAccessDefect all you have to do is to import this module.
|
||||||
##
|
##
|
||||||
## Tested on these OSes: Linux, Windows, OSX
|
## Tested on these OSes: Linux, Windows, OSX
|
||||||
|
|
||||||
{.used.}
|
{.used.}
|
||||||
|
|
||||||
# do allocate memory upfront:
|
# do allocate memory upfront:
|
||||||
var se: ref NilAccessError
|
var se: ref NilAccessDefect
|
||||||
new(se)
|
new(se)
|
||||||
se.name = "NilAccessError"
|
se.name = "NilAccessDefect"
|
||||||
se.msg = "Could not access value because it is nil."
|
se.msg = "Could not access value because it is nil."
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
|
|||||||
@@ -88,7 +88,7 @@
|
|||||||
##
|
##
|
||||||
## test "out of bounds error is thrown on bad access":
|
## test "out of bounds error is thrown on bad access":
|
||||||
## let v = @[1, 2, 3] # you can do initialization here
|
## let v = @[1, 2, 3] # you can do initialization here
|
||||||
## expect(IndexError):
|
## expect(IndexDefect):
|
||||||
## discard v[4]
|
## discard v[4]
|
||||||
##
|
##
|
||||||
## echo "suite teardown: run once after the tests"
|
## echo "suite teardown: run once after the tests"
|
||||||
@@ -190,7 +190,7 @@ proc delOutputFormatter*(formatter: OutputFormatter) =
|
|||||||
|
|
||||||
proc resetOutputFormatters* {.since: (1, 1).} =
|
proc resetOutputFormatters* {.since: (1, 1).} =
|
||||||
formatters = @[]
|
formatters = @[]
|
||||||
|
|
||||||
proc newConsoleOutputFormatter*(outputLevel: OutputLevel = OutputLevel.PRINT_ALL,
|
proc newConsoleOutputFormatter*(outputLevel: OutputLevel = OutputLevel.PRINT_ALL,
|
||||||
colorOutput = true): <//>ConsoleOutputFormatter =
|
colorOutput = true): <//>ConsoleOutputFormatter =
|
||||||
ConsoleOutputFormatter(
|
ConsoleOutputFormatter(
|
||||||
@@ -717,7 +717,7 @@ macro expect*(exceptions: varargs[typed], body: untyped): untyped =
|
|||||||
## of 3: raise newException(IOError, "I can't do that Dave.")
|
## of 3: raise newException(IOError, "I can't do that Dave.")
|
||||||
## else: assert 2 + 2 == 5
|
## else: assert 2 + 2 == 5
|
||||||
##
|
##
|
||||||
## expect IOError, OSError, ValueError, AssertionError:
|
## expect IOError, OSError, ValueError, AssertionDefect:
|
||||||
## defectiveRobot()
|
## defectiveRobot()
|
||||||
let exp = callsite()
|
let exp = callsite()
|
||||||
template expectBody(errorTypes, lineInfoLit, body): NimNode {.dirty.} =
|
template expectBody(errorTypes, lineInfoLit, body): NimNode {.dirty.} =
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ template `[]`*[I](a: Wrapnil, i: I): untyped =
|
|||||||
## See top-level example.
|
## See top-level example.
|
||||||
let a1 = a # to avoid double evaluations
|
let a1 = a # to avoid double evaluations
|
||||||
if a1.validImpl:
|
if a1.validImpl:
|
||||||
# correctly will raise IndexError if a is valid but wraps an empty container
|
# correctly will raise IndexDefect if a is valid but wraps an empty container
|
||||||
wrapnil(a1.valueImpl[i])
|
wrapnil(a1.valueImpl[i])
|
||||||
else:
|
else:
|
||||||
default(Wrapnil[type(a1.valueImpl[i])])
|
default(Wrapnil[type(a1.valueImpl[i])])
|
||||||
|
|||||||
@@ -868,8 +868,8 @@ proc `of`*[T, S](x: T, y: S): bool {.magic: "Of", noSideEffect.}
|
|||||||
## Checks if `x` has a type of `y`.
|
## Checks if `x` has a type of `y`.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## assert(FloatingPointError of Exception)
|
## assert(FloatingPointDefect of Exception)
|
||||||
## assert(DivByZeroError of Exception)
|
## assert(DivByZeroDefect of Exception)
|
||||||
|
|
||||||
proc cmp*[T](x, y: T): int {.procvar.} =
|
proc cmp*[T](x, y: T): int {.procvar.} =
|
||||||
## Generic compare proc.
|
## Generic compare proc.
|
||||||
@@ -1673,8 +1673,8 @@ proc instantiationInfo*(index = -1, fullPaths = false): tuple[
|
|||||||
## result = a[pos]
|
## result = a[pos]
|
||||||
##
|
##
|
||||||
## when isMainModule:
|
## when isMainModule:
|
||||||
## testException(IndexError, tester(30))
|
## testException(IndexDefect, tester(30))
|
||||||
## testException(IndexError, tester(1))
|
## testException(IndexDefect, tester(1))
|
||||||
## # --> Test failure at example.nim:20 with 'tester(1)'
|
## # --> Test failure at example.nim:20 with 'tester(1)'
|
||||||
|
|
||||||
proc compiles*(x: untyped): bool {.magic: "Compiles", noSideEffect, compileTime.} =
|
proc compiles*(x: untyped): bool {.magic: "Compiles", noSideEffect, compileTime.} =
|
||||||
@@ -2493,7 +2493,7 @@ proc `[]=`*[Idx, T, U, V](a: var array[Idx, T], x: HSlice[U, V], b: openArray[T]
|
|||||||
if L == b.len:
|
if L == b.len:
|
||||||
for i in 0..<L: a[Idx(i + xa)] = b[i]
|
for i in 0..<L: a[Idx(i + xa)] = b[i]
|
||||||
else:
|
else:
|
||||||
sysFatal(RangeError, "different lengths for slice assignment")
|
sysFatal(RangeDefect, "different lengths for slice assignment")
|
||||||
|
|
||||||
proc `[]`*[T, U, V](s: openArray[T], x: HSlice[U, V]): seq[T] =
|
proc `[]`*[T, U, V](s: openArray[T], x: HSlice[U, V]): seq[T] =
|
||||||
## Slice operation for sequences.
|
## Slice operation for sequences.
|
||||||
@@ -2655,7 +2655,7 @@ when compileOption("rangechecks"):
|
|||||||
## Helper for performing user-defined range checks.
|
## Helper for performing user-defined range checks.
|
||||||
## Such checks will be performed only when the ``rangechecks``
|
## Such checks will be performed only when the ``rangechecks``
|
||||||
## compile-time option is enabled.
|
## compile-time option is enabled.
|
||||||
if not cond: sysFatal(RangeError, "range check failed")
|
if not cond: sysFatal(RangeDefect, "range check failed")
|
||||||
else:
|
else:
|
||||||
template rangeCheck*(cond) = discard
|
template rangeCheck*(cond) = discard
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,10 @@
|
|||||||
|
|
||||||
proc raiseOverflow {.compilerproc, noinline.} =
|
proc raiseOverflow {.compilerproc, noinline.} =
|
||||||
# a single proc to reduce code size to a minimum
|
# a single proc to reduce code size to a minimum
|
||||||
sysFatal(OverflowError, "over- or underflow")
|
sysFatal(OverflowDefect, "over- or underflow")
|
||||||
|
|
||||||
proc raiseDivByZero {.compilerproc, noinline.} =
|
proc raiseDivByZero {.compilerproc, noinline.} =
|
||||||
sysFatal(DivByZeroError, "division by zero")
|
sysFatal(DivByZeroDefect, "division by zero")
|
||||||
|
|
||||||
when defined(builtinOverflow):
|
when defined(builtinOverflow):
|
||||||
# Builtin compiler functions for improved performance
|
# Builtin compiler functions for improved performance
|
||||||
@@ -410,16 +410,16 @@ when not declared(mulInt):
|
|||||||
# written in other languages.
|
# written in other languages.
|
||||||
|
|
||||||
proc raiseFloatInvalidOp {.compilerproc, noinline.} =
|
proc raiseFloatInvalidOp {.compilerproc, noinline.} =
|
||||||
sysFatal(FloatInvalidOpError, "FPU operation caused a NaN result")
|
sysFatal(FloatInvalidOpDefect, "FPU operation caused a NaN result")
|
||||||
|
|
||||||
proc nanCheck(x: float64) {.compilerproc, inline.} =
|
proc nanCheck(x: float64) {.compilerproc, inline.} =
|
||||||
if x != x: raiseFloatInvalidOp()
|
if x != x: raiseFloatInvalidOp()
|
||||||
|
|
||||||
proc raiseFloatOverflow(x: float64) {.compilerproc, noinline.} =
|
proc raiseFloatOverflow(x: float64) {.compilerproc, noinline.} =
|
||||||
if x > 0.0:
|
if x > 0.0:
|
||||||
sysFatal(FloatOverflowError, "FPU operation caused an overflow")
|
sysFatal(FloatOverflowDefect, "FPU operation caused an overflow")
|
||||||
else:
|
else:
|
||||||
sysFatal(FloatUnderflowError, "FPU operations caused an underflow")
|
sysFatal(FloatUnderflowDefect, "FPU operations caused an underflow")
|
||||||
|
|
||||||
proc infCheck(x: float64) {.compilerproc, inline.} =
|
proc infCheck(x: float64) {.compilerproc, inline.} =
|
||||||
if x != 0.0 and x*0.5 == x: raiseFloatOverflow(x)
|
if x != 0.0 and x*0.5 == x: raiseFloatOverflow(x)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ proc succ*[T: Ordinal](x: T, y = 1): T {.magic: "Succ", noSideEffect.}
|
|||||||
## Returns the ``y``-th successor (default: 1) of the value ``x``.
|
## Returns the ``y``-th successor (default: 1) of the value ``x``.
|
||||||
## ``T`` has to be an `ordinal type <#Ordinal>`_.
|
## ``T`` has to be an `ordinal type <#Ordinal>`_.
|
||||||
##
|
##
|
||||||
## If such a value does not exist, ``OverflowError`` is raised
|
## If such a value does not exist, ``OverflowDefect`` is raised
|
||||||
## or a compile time error occurs.
|
## or a compile time error occurs.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
@@ -14,7 +14,7 @@ proc pred*[T: Ordinal](x: T, y = 1): T {.magic: "Pred", noSideEffect.}
|
|||||||
## Returns the ``y``-th predecessor (default: 1) of the value ``x``.
|
## Returns the ``y``-th predecessor (default: 1) of the value ``x``.
|
||||||
## ``T`` has to be an `ordinal type <#Ordinal>`_.
|
## ``T`` has to be an `ordinal type <#Ordinal>`_.
|
||||||
##
|
##
|
||||||
## If such a value does not exist, ``OverflowError`` is raised
|
## If such a value does not exist, ``OverflowDefect`` is raised
|
||||||
## or a compile time error occurs.
|
## or a compile time error occurs.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
@@ -25,7 +25,7 @@ proc pred*[T: Ordinal](x: T, y = 1): T {.magic: "Pred", noSideEffect.}
|
|||||||
proc inc*[T: Ordinal](x: var T, y = 1) {.magic: "Inc", noSideEffect.}
|
proc inc*[T: Ordinal](x: var T, y = 1) {.magic: "Inc", noSideEffect.}
|
||||||
## Increments the ordinal ``x`` by ``y``.
|
## Increments the ordinal ``x`` by ``y``.
|
||||||
##
|
##
|
||||||
## If such a value does not exist, ``OverflowError`` is raised or a compile
|
## If such a value does not exist, ``OverflowDefect`` is raised or a compile
|
||||||
## time error occurs. This is a short notation for: ``x = succ(x, y)``.
|
## time error occurs. This is a short notation for: ``x = succ(x, y)``.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
@@ -36,7 +36,7 @@ proc inc*[T: Ordinal](x: var T, y = 1) {.magic: "Inc", noSideEffect.}
|
|||||||
proc dec*[T: Ordinal](x: var T, y = 1) {.magic: "Dec", noSideEffect.}
|
proc dec*[T: Ordinal](x: var T, y = 1) {.magic: "Dec", noSideEffect.}
|
||||||
## Decrements the ordinal ``x`` by ``y``.
|
## Decrements the ordinal ``x`` by ``y``.
|
||||||
##
|
##
|
||||||
## If such a value does not exist, ``OverflowError`` is raised or a compile
|
## If such a value does not exist, ``OverflowDefect`` is raised or a compile
|
||||||
## time error occurs. This is a short notation for: ``x = pred(x, y)``.
|
## time error occurs. This is a short notation for: ``x = pred(x, y)``.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ when not defined(nimHasSinkInference):
|
|||||||
{.pragma: nosinks.}
|
{.pragma: nosinks.}
|
||||||
|
|
||||||
proc raiseAssert*(msg: string) {.noinline, noreturn, nosinks.} =
|
proc raiseAssert*(msg: string) {.noinline, noreturn, nosinks.} =
|
||||||
sysFatal(AssertionError, msg)
|
sysFatal(AssertionDefect, msg)
|
||||||
|
|
||||||
proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
|
proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
|
||||||
# trick the compiler to not list ``AssertionError`` when called
|
# trick the compiler to not list ``AssertionDefect`` when called
|
||||||
# by ``assert``.
|
# by ``assert``.
|
||||||
type Hide = proc (msg: string) {.noinline, raises: [], noSideEffect,
|
type Hide = proc (msg: string) {.noinline, raises: [], noSideEffect,
|
||||||
tags: [].}
|
tags: [].}
|
||||||
@@ -40,9 +40,9 @@ template assertImpl(cond: bool, msg: string, expr: string, enabled: static[bool]
|
|||||||
failedAssertImpl(ploc & " `" & expr & "` " & msg)
|
failedAssertImpl(ploc & " `" & expr & "` " & msg)
|
||||||
|
|
||||||
template assert*(cond: untyped, msg = "") =
|
template assert*(cond: untyped, msg = "") =
|
||||||
## Raises ``AssertionError`` with `msg` if `cond` is false. Note
|
## Raises ``AssertionDefect`` with `msg` if `cond` is false. Note
|
||||||
## that ``AssertionError`` is hidden from the effect system, so it doesn't
|
## that ``AssertionDefect`` is hidden from the effect system, so it doesn't
|
||||||
## produce ``{.raises: [AssertionError].}``. This exception is only supposed
|
## produce ``{.raises: [AssertionDefect].}``. This exception is only supposed
|
||||||
## to be caught by unit testing frameworks.
|
## to be caught by unit testing frameworks.
|
||||||
##
|
##
|
||||||
## The compiler may not generate any code at all for ``assert`` if it is
|
## The compiler may not generate any code at all for ``assert`` if it is
|
||||||
@@ -80,7 +80,7 @@ template onFailedAssert*(msg, code: untyped): untyped {.dirty.} =
|
|||||||
code
|
code
|
||||||
|
|
||||||
template doAssertRaises*(exception: typedesc, code: untyped) =
|
template doAssertRaises*(exception: typedesc, code: untyped) =
|
||||||
## Raises ``AssertionError`` if specified ``code`` does not raise the
|
## Raises ``AssertionDefect`` if specified ``code`` does not raise the
|
||||||
## specified exception. Example:
|
## specified exception. Example:
|
||||||
##
|
##
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
|
|||||||
@@ -233,10 +233,10 @@ proc FieldDiscriminantCheck(oldDiscVal, newDiscVal: int,
|
|||||||
let newBranch = selectBranch(newDiscVal, L, a)
|
let newBranch = selectBranch(newDiscVal, L, a)
|
||||||
when defined(nimOldCaseObjects):
|
when defined(nimOldCaseObjects):
|
||||||
if newBranch != oldBranch and oldDiscVal != 0:
|
if newBranch != oldBranch and oldDiscVal != 0:
|
||||||
sysFatal(FieldError, "assignment to discriminant changes object branch")
|
sysFatal(FieldDefect, "assignment to discriminant changes object branch")
|
||||||
else:
|
else:
|
||||||
if newBranch != oldBranch:
|
if newBranch != oldBranch:
|
||||||
if oldDiscVal != 0:
|
if oldDiscVal != 0:
|
||||||
sysFatal(FieldError, "assignment to discriminant changes object branch")
|
sysFatal(FieldDefect, "assignment to discriminant changes object branch")
|
||||||
else:
|
else:
|
||||||
sysFatal(FieldError, "assignment to discriminant changes object branch; compile with -d:nimOldCaseObjects for a transition period")
|
sysFatal(FieldDefect, "assignment to discriminant changes object branch; compile with -d:nimOldCaseObjects for a transition period")
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ template lockChannel(q, action): untyped =
|
|||||||
|
|
||||||
proc sendImpl(q: PRawChannel, typ: PNimType, msg: pointer, noBlock: bool): bool =
|
proc sendImpl(q: PRawChannel, typ: PNimType, msg: pointer, noBlock: bool): bool =
|
||||||
if q.mask == ChannelDeadMask:
|
if q.mask == ChannelDeadMask:
|
||||||
sysFatal(DeadThreadError, "cannot send message; thread died")
|
sysFatal(DeadThreadDefect, "cannot send message; thread died")
|
||||||
acquireSys(q.lock)
|
acquireSys(q.lock)
|
||||||
if q.maxItems > 0:
|
if q.maxItems > 0:
|
||||||
# Wait until count is less than maxItems
|
# Wait until count is less than maxItems
|
||||||
|
|||||||
@@ -12,34 +12,34 @@ include system/indexerrors
|
|||||||
|
|
||||||
proc raiseRangeError(val: BiggestInt) {.compilerproc, noinline.} =
|
proc raiseRangeError(val: BiggestInt) {.compilerproc, noinline.} =
|
||||||
when hostOS == "standalone":
|
when hostOS == "standalone":
|
||||||
sysFatal(RangeError, "value out of range")
|
sysFatal(RangeDefect, "value out of range")
|
||||||
else:
|
else:
|
||||||
sysFatal(RangeError, "value out of range: ", $val)
|
sysFatal(RangeDefect, "value out of range: ", $val)
|
||||||
|
|
||||||
proc raiseIndexError3(i, a, b: int) {.compilerproc, noinline.} =
|
proc raiseIndexError3(i, a, b: int) {.compilerproc, noinline.} =
|
||||||
sysFatal(IndexError, formatErrorIndexBound(i, a, b))
|
sysFatal(IndexDefect, formatErrorIndexBound(i, a, b))
|
||||||
|
|
||||||
proc raiseIndexError2(i, n: int) {.compilerproc, noinline.} =
|
proc raiseIndexError2(i, n: int) {.compilerproc, noinline.} =
|
||||||
sysFatal(IndexError, formatErrorIndexBound(i, n))
|
sysFatal(IndexDefect, formatErrorIndexBound(i, n))
|
||||||
|
|
||||||
proc raiseIndexError() {.compilerproc, noinline.} =
|
proc raiseIndexError() {.compilerproc, noinline.} =
|
||||||
sysFatal(IndexError, "index out of bounds")
|
sysFatal(IndexDefect, "index out of bounds")
|
||||||
|
|
||||||
proc raiseFieldError(f: string) {.compilerproc, noinline.} =
|
proc raiseFieldError(f: string) {.compilerproc, noinline.} =
|
||||||
sysFatal(FieldError, f)
|
sysFatal(FieldDefect, f)
|
||||||
|
|
||||||
proc raiseRangeErrorI(i, a, b: BiggestInt) {.compilerproc, noinline.} =
|
proc raiseRangeErrorI(i, a, b: BiggestInt) {.compilerproc, noinline.} =
|
||||||
sysFatal(RangeError, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
sysFatal(RangeDefect, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
||||||
|
|
||||||
proc raiseRangeErrorF(i, a, b: float) {.compilerproc, noinline.} =
|
proc raiseRangeErrorF(i, a, b: float) {.compilerproc, noinline.} =
|
||||||
sysFatal(RangeError, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
sysFatal(RangeDefect, "value out of range: " & $i & " notin " & $a & " .. " & $b)
|
||||||
|
|
||||||
proc raiseRangeErrorU(i, a, b: uint64) {.compilerproc, noinline.} =
|
proc raiseRangeErrorU(i, a, b: uint64) {.compilerproc, noinline.} =
|
||||||
# todo: better error reporting
|
# todo: better error reporting
|
||||||
sysFatal(RangeError, "value out of range")
|
sysFatal(RangeDefect, "value out of range")
|
||||||
|
|
||||||
proc raiseObjectConversionError() {.compilerproc, noinline.} =
|
proc raiseObjectConversionError() {.compilerproc, noinline.} =
|
||||||
sysFatal(ObjectConversionError, "invalid object conversion")
|
sysFatal(ObjectConversionDefect, "invalid object conversion")
|
||||||
|
|
||||||
proc chckIndx(i, a, b: int): int =
|
proc chckIndx(i, a, b: int): int =
|
||||||
if i >= a and i <= b:
|
if i >= a and i <= b:
|
||||||
@@ -63,24 +63,24 @@ proc chckRangeU(i, a, b: uint64): uint64 {.compilerproc.} =
|
|||||||
if i >= a and i <= b:
|
if i >= a and i <= b:
|
||||||
return i
|
return i
|
||||||
else:
|
else:
|
||||||
sysFatal(RangeError, "value out of range")
|
sysFatal(RangeDefect, "value out of range")
|
||||||
|
|
||||||
proc chckRangeF(x, a, b: float): float =
|
proc chckRangeF(x, a, b: float): float =
|
||||||
if x >= a and x <= b:
|
if x >= a and x <= b:
|
||||||
return x
|
return x
|
||||||
else:
|
else:
|
||||||
when hostOS == "standalone":
|
when hostOS == "standalone":
|
||||||
sysFatal(RangeError, "value out of range")
|
sysFatal(RangeDefect, "value out of range")
|
||||||
else:
|
else:
|
||||||
sysFatal(RangeError, "value out of range: ", $x)
|
sysFatal(RangeDefect, "value out of range: ", $x)
|
||||||
|
|
||||||
proc chckNil(p: pointer) =
|
proc chckNil(p: pointer) =
|
||||||
if p == nil:
|
if p == nil:
|
||||||
sysFatal(NilAccessError, "attempt to write to a nil address")
|
sysFatal(NilAccessDefect, "attempt to write to a nil address")
|
||||||
|
|
||||||
proc chckNilDisp(p: pointer) {.compilerproc.} =
|
proc chckNilDisp(p: pointer) {.compilerproc.} =
|
||||||
if p == nil:
|
if p == nil:
|
||||||
sysFatal(NilAccessError, "cannot dispatch; dispatcher is nil")
|
sysFatal(NilAccessDefect, "cannot dispatch; dispatcher is nil")
|
||||||
|
|
||||||
when not defined(nimV2):
|
when not defined(nimV2):
|
||||||
|
|
||||||
@@ -90,12 +90,12 @@ when not defined(nimV2):
|
|||||||
if x == subclass: return # optimized fast path
|
if x == subclass: return # optimized fast path
|
||||||
while x != subclass:
|
while x != subclass:
|
||||||
if x == nil:
|
if x == nil:
|
||||||
sysFatal(ObjectConversionError, "invalid object conversion")
|
sysFatal(ObjectConversionDefect, "invalid object conversion")
|
||||||
x = x.base
|
x = x.base
|
||||||
|
|
||||||
proc chckObjAsgn(a, b: PNimType) {.compilerproc, inline.} =
|
proc chckObjAsgn(a, b: PNimType) {.compilerproc, inline.} =
|
||||||
if a != b:
|
if a != b:
|
||||||
sysFatal(ObjectAssignmentError, "invalid object assignment")
|
sysFatal(ObjectAssignmentDefect, "invalid object assignment")
|
||||||
|
|
||||||
type ObjCheckCache = array[0..1, PNimType]
|
type ObjCheckCache = array[0..1, PNimType]
|
||||||
|
|
||||||
@@ -130,4 +130,4 @@ when not defined(nimV2):
|
|||||||
|
|
||||||
when defined(nimV2):
|
when defined(nimV2):
|
||||||
proc raiseObjectCaseTransition() {.compilerproc.} =
|
proc raiseObjectCaseTransition() {.compilerproc.} =
|
||||||
sysFatal(FieldError, "assignment to discriminant changes object branch")
|
sysFatal(FieldDefect, "assignment to discriminant changes object branch")
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ const
|
|||||||
proc quitOrDebug() {.noreturn, importc: "abort", header: "<stdlib.h>", nodecl.}
|
proc quitOrDebug() {.noreturn, importc: "abort", header: "<stdlib.h>", nodecl.}
|
||||||
|
|
||||||
proc raiseException(e: ref Exception, ename: cstring) {.compilerRtl.} =
|
proc raiseException(e: ref Exception, ename: cstring) {.compilerRtl.} =
|
||||||
sysFatal(ReraiseError, "exception handling is not available")
|
sysFatal(ReraiseDefect, "exception handling is not available")
|
||||||
|
|
||||||
proc reraiseException() {.compilerRtl.} =
|
proc reraiseException() {.compilerRtl.} =
|
||||||
sysFatal(ReraiseError, "no exception to reraise")
|
sysFatal(ReraiseDefect, "no exception to reraise")
|
||||||
|
|
||||||
proc writeStackTrace() = discard
|
proc writeStackTrace() = discard
|
||||||
|
|
||||||
@@ -43,4 +43,4 @@ proc unsetControlCHook() = discard
|
|||||||
proc setControlCHook(hook: proc () {.noconv.}) = discard
|
proc setControlCHook(hook: proc () {.noconv.}) = discard
|
||||||
|
|
||||||
proc closureIterSetupExc(e: ref Exception) {.compilerproc, inline.} =
|
proc closureIterSetupExc(e: ref Exception) {.compilerproc, inline.} =
|
||||||
sysFatal(ReraiseError, "exception handling is not available")
|
sysFatal(ReraiseDefect, "exception handling is not available")
|
||||||
|
|||||||
@@ -62,19 +62,19 @@ type
|
|||||||
## Raised if a dynamic library could not be loaded.
|
## Raised if a dynamic library could not be loaded.
|
||||||
ResourceExhaustedError* = object of CatchableError ## \
|
ResourceExhaustedError* = object of CatchableError ## \
|
||||||
## Raised if a resource request could not be fulfilled.
|
## Raised if a resource request could not be fulfilled.
|
||||||
ArithmeticError* = object of Defect ## \
|
ArithmeticDefect* = object of Defect ## \
|
||||||
## Raised if any kind of arithmetic error occurred.
|
## Raised if any kind of arithmetic error occurred.
|
||||||
DivByZeroError* = object of ArithmeticError ## \
|
DivByZeroDefect* = object of ArithmeticDefect ## \
|
||||||
## Raised for runtime integer divide-by-zero errors.
|
## Raised for runtime integer divide-by-zero errors.
|
||||||
|
|
||||||
OverflowError* = object of ArithmeticError ## \
|
OverflowDefect* = object of ArithmeticDefect ## \
|
||||||
## Raised for runtime integer overflows.
|
## Raised for runtime integer overflows.
|
||||||
##
|
##
|
||||||
## This happens for calculations whose results are too large to fit in the
|
## This happens for calculations whose results are too large to fit in the
|
||||||
## provided bits.
|
## provided bits.
|
||||||
AccessViolationError* = object of Defect ## \
|
AccessViolationDefect* = object of Defect ## \
|
||||||
## Raised for invalid memory access errors
|
## Raised for invalid memory access errors
|
||||||
AssertionError* = object of Defect ## \
|
AssertionDefect* = object of Defect ## \
|
||||||
## Raised when assertion is proved wrong.
|
## Raised when assertion is proved wrong.
|
||||||
##
|
##
|
||||||
## Usually the result of using the `assert() template
|
## Usually the result of using the `assert() template
|
||||||
@@ -87,54 +87,77 @@ type
|
|||||||
## Mostly used by the `tables <tables.html>`_ module, it can also be raised
|
## Mostly used by the `tables <tables.html>`_ module, it can also be raised
|
||||||
## by other collection modules like `sets <sets.html>`_ or `strtabs
|
## by other collection modules like `sets <sets.html>`_ or `strtabs
|
||||||
## <strtabs.html>`_.
|
## <strtabs.html>`_.
|
||||||
OutOfMemError* = object of Defect ## \
|
OutOfMemDefect* = object of Defect ## \
|
||||||
## Raised for unsuccessful attempts to allocate memory.
|
## Raised for unsuccessful attempts to allocate memory.
|
||||||
IndexError* = object of Defect ## \
|
IndexDefect* = object of Defect ## \
|
||||||
## Raised if an array index is out of bounds.
|
## Raised if an array index is out of bounds.
|
||||||
|
|
||||||
FieldError* = object of Defect ## \
|
FieldDefect* = object of Defect ## \
|
||||||
## Raised if a record field is not accessible because its discriminant's
|
## Raised if a record field is not accessible because its discriminant's
|
||||||
## value does not fit.
|
## value does not fit.
|
||||||
RangeError* = object of Defect ## \
|
RangeDefect* = object of Defect ## \
|
||||||
## Raised if a range check error occurred.
|
## Raised if a range check error occurred.
|
||||||
StackOverflowError* = object of Defect ## \
|
StackOverflowDefect* = object of Defect ## \
|
||||||
## Raised if the hardware stack used for subroutine calls overflowed.
|
## Raised if the hardware stack used for subroutine calls overflowed.
|
||||||
ReraiseError* = object of Defect ## \
|
ReraiseDefect* = object of Defect ## \
|
||||||
## Raised if there is no exception to reraise.
|
## Raised if there is no exception to reraise.
|
||||||
ObjectAssignmentError* = object of Defect ## \
|
ObjectAssignmentDefect* = object of Defect ## \
|
||||||
## Raised if an object gets assigned to its parent's object.
|
## Raised if an object gets assigned to its parent's object.
|
||||||
ObjectConversionError* = object of Defect ## \
|
ObjectConversionDefect* = object of Defect ## \
|
||||||
## Raised if an object is converted to an incompatible object type.
|
## Raised if an object is converted to an incompatible object type.
|
||||||
## You can use ``of`` operator to check if conversion will succeed.
|
## You can use ``of`` operator to check if conversion will succeed.
|
||||||
FloatingPointError* = object of Defect ## \
|
FloatingPointDefect* = object of Defect ## \
|
||||||
## Base class for floating point exceptions.
|
## Base class for floating point exceptions.
|
||||||
FloatInvalidOpError* = object of FloatingPointError ## \
|
FloatInvalidOpDefect* = object of FloatingPointDefect ## \
|
||||||
## Raised by invalid operations according to IEEE.
|
## Raised by invalid operations according to IEEE.
|
||||||
##
|
##
|
||||||
## Raised by ``0.0/0.0``, for example.
|
## Raised by ``0.0/0.0``, for example.
|
||||||
FloatDivByZeroError* = object of FloatingPointError ## \
|
FloatDivByZeroDefect* = object of FloatingPointDefect ## \
|
||||||
## Raised by division by zero.
|
## Raised by division by zero.
|
||||||
##
|
##
|
||||||
## Divisor is zero and dividend is a finite nonzero number.
|
## Divisor is zero and dividend is a finite nonzero number.
|
||||||
FloatOverflowError* = object of FloatingPointError ## \
|
FloatOverflowDefect* = object of FloatingPointDefect ## \
|
||||||
## Raised for overflows.
|
## Raised for overflows.
|
||||||
##
|
##
|
||||||
## The operation produced a result that exceeds the range of the exponent.
|
## The operation produced a result that exceeds the range of the exponent.
|
||||||
FloatUnderflowError* = object of FloatingPointError ## \
|
FloatUnderflowDefect* = object of FloatingPointDefect ## \
|
||||||
## Raised for underflows.
|
## Raised for underflows.
|
||||||
##
|
##
|
||||||
## The operation produced a result that is too small to be represented as a
|
## The operation produced a result that is too small to be represented as a
|
||||||
## normal number.
|
## normal number.
|
||||||
FloatInexactError* = object of FloatingPointError ## \
|
FloatInexactDefect* = object of FloatingPointDefect ## \
|
||||||
## Raised for inexact results.
|
## Raised for inexact results.
|
||||||
##
|
##
|
||||||
## The operation produced a result that cannot be represented with infinite
|
## The operation produced a result that cannot be represented with infinite
|
||||||
## precision -- for example: ``2.0 / 3.0, log(1.1)``
|
## precision -- for example: ``2.0 / 3.0, log(1.1)``
|
||||||
##
|
##
|
||||||
## **Note**: Nim currently does not detect these!
|
## **Note**: Nim currently does not detect these!
|
||||||
DeadThreadError* = object of Defect ## \
|
DeadThreadDefect* = object of Defect ## \
|
||||||
## Raised if it is attempted to send a message to a dead thread.
|
## Raised if it is attempted to send a message to a dead thread.
|
||||||
NilAccessError* = object of Defect ## \
|
NilAccessDefect* = object of Defect ## \
|
||||||
## Raised on dereferences of ``nil`` pointers.
|
## Raised on dereferences of ``nil`` pointers.
|
||||||
##
|
##
|
||||||
## This is only raised if the `segfaults module <segfaults.html>`_ was imported!
|
## This is only raised if the `segfaults module <segfaults.html>`_ was imported!
|
||||||
|
|
||||||
|
ArithmeticError* {.deprecated: "See corresponding Defect".} = ArithmeticDefect
|
||||||
|
DivByZeroError* {.deprecated: "See corresponding Defect".} = ArithmeticDefect
|
||||||
|
OverflowError* {.deprecated: "See corresponding Defect".} = OverflowDefect
|
||||||
|
AccessViolationError* {.deprecated: "See corresponding Defect".} = AccessViolationDefect
|
||||||
|
AssertionError* {.deprecated: "See corresponding Defect".} = AssertionDefect
|
||||||
|
OutOfMemError* {.deprecated: "See corresponding Defect".} = OutOfMemDefect
|
||||||
|
IndexError* {.deprecated: "See corresponding Defect".} = IndexDefect
|
||||||
|
|
||||||
|
FieldError* {.deprecated: "See corresponding Defect".} = FieldDefect
|
||||||
|
RangeError* {.deprecated: "See corresponding Defect".} = RangeDefect
|
||||||
|
StackOverflowError* {.deprecated: "See corresponding Defect".} = StackOverflowDefect
|
||||||
|
ReraiseError* {.deprecated: "See corresponding Defect".} = ReraiseDefect
|
||||||
|
ObjectAssignmentError* {.deprecated: "See corresponding Defect".} = ObjectAssignmentDefect
|
||||||
|
ObjectConversionError* {.deprecated: "See corresponding Defect".} = ObjectConversionDefect
|
||||||
|
FloatingPointError* {.deprecated: "See corresponding Defect".} = FloatingPointDefect
|
||||||
|
FloatInvalidOpError* {.deprecated: "See corresponding Defect".} = FloatInvalidOpDefect
|
||||||
|
FloatDivByZeroError* {.deprecated: "See corresponding Defect".} = FloatDivByZeroDefect
|
||||||
|
FloatOverflowError* {.deprecated: "See corresponding Defect".} = FloatOverflowDefect
|
||||||
|
FloatUnderflowError* {.deprecated: "See corresponding Defect".} = FloatUnderflowDefect
|
||||||
|
FloatInexactError* {.deprecated: "See corresponding Defect".} = FloatInexactDefect
|
||||||
|
DeadThreadError* {.deprecated: "See corresponding Defect".} = DeadThreadDefect
|
||||||
|
NilAccessError* {.deprecated: "See corresponding Defect".} = NilAccessDefect
|
||||||
|
|||||||
@@ -483,7 +483,7 @@ proc raiseException(e: sink(ref Exception), ename: cstring) {.compilerRtl.} =
|
|||||||
|
|
||||||
proc reraiseException() {.compilerRtl.} =
|
proc reraiseException() {.compilerRtl.} =
|
||||||
if currException == nil:
|
if currException == nil:
|
||||||
sysFatal(ReraiseError, "no exception to reraise")
|
sysFatal(ReraiseDefect, "no exception to reraise")
|
||||||
else:
|
else:
|
||||||
when gotoBasedExceptions:
|
when gotoBasedExceptions:
|
||||||
inc nimInErrorMode
|
inc nimInErrorMode
|
||||||
|
|||||||
@@ -844,7 +844,7 @@ when not defined(useNimRtl):
|
|||||||
inc(gch.recGcLock)
|
inc(gch.recGcLock)
|
||||||
proc GC_enable() =
|
proc GC_enable() =
|
||||||
if gch.recGcLock <= 0:
|
if gch.recGcLock <= 0:
|
||||||
raise newException(AssertionError,
|
raise newException(AssertionDefect,
|
||||||
"API usage error: GC_enable called but GC is already enabled")
|
"API usage error: GC_enable called but GC is already enabled")
|
||||||
dec(gch.recGcLock)
|
dec(gch.recGcLock)
|
||||||
|
|
||||||
|
|||||||
@@ -496,7 +496,7 @@ when not defined(useNimRtl):
|
|||||||
inc(gch.recGcLock)
|
inc(gch.recGcLock)
|
||||||
proc GC_enable() =
|
proc GC_enable() =
|
||||||
if gch.recGcLock <= 0:
|
if gch.recGcLock <= 0:
|
||||||
raise newException(AssertionError,
|
raise newException(AssertionDefect,
|
||||||
"API usage error: GC_enable called but GC is already enabled")
|
"API usage error: GC_enable called but GC is already enabled")
|
||||||
dec(gch.recGcLock)
|
dec(gch.recGcLock)
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,10 @@
|
|||||||
|
|
||||||
proc raiseOverflow {.compilerproc, noinline.} =
|
proc raiseOverflow {.compilerproc, noinline.} =
|
||||||
# a single proc to reduce code size to a minimum
|
# a single proc to reduce code size to a minimum
|
||||||
sysFatal(OverflowError, "over- or underflow")
|
sysFatal(OverflowDefect, "over- or underflow")
|
||||||
|
|
||||||
proc raiseDivByZero {.compilerproc, noinline.} =
|
proc raiseDivByZero {.compilerproc, noinline.} =
|
||||||
sysFatal(DivByZeroError, "division by zero")
|
sysFatal(DivByZeroDefect, "division by zero")
|
||||||
|
|
||||||
{.pragma: nimbaseH, importc, nodecl, noSideEffect, compilerproc.}
|
{.pragma: nimbaseH, importc, nodecl, noSideEffect, compilerproc.}
|
||||||
|
|
||||||
@@ -123,10 +123,10 @@ divImplFallback(nimDivInt, int)
|
|||||||
divImplFallback(nimDivInt64, int64)
|
divImplFallback(nimDivInt64, int64)
|
||||||
|
|
||||||
proc raiseFloatInvalidOp {.compilerproc, noinline.} =
|
proc raiseFloatInvalidOp {.compilerproc, noinline.} =
|
||||||
sysFatal(FloatInvalidOpError, "FPU operation caused a NaN result")
|
sysFatal(FloatInvalidOpDefect, "FPU operation caused a NaN result")
|
||||||
|
|
||||||
proc raiseFloatOverflow(x: float64) {.compilerproc, noinline.} =
|
proc raiseFloatOverflow(x: float64) {.compilerproc, noinline.} =
|
||||||
if x > 0.0:
|
if x > 0.0:
|
||||||
sysFatal(FloatOverflowError, "FPU operation caused an overflow")
|
sysFatal(FloatOverflowDefect, "FPU operation caused an overflow")
|
||||||
else:
|
else:
|
||||||
sysFatal(FloatUnderflowError, "FPU operations caused an underflow")
|
sysFatal(FloatUnderflowDefect, "FPU operations caused an underflow")
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ proc raiseException(e: ref Exception, ename: cstring) {.
|
|||||||
|
|
||||||
proc reraiseException() {.compilerproc, asmNoStackFrame.} =
|
proc reraiseException() {.compilerproc, asmNoStackFrame.} =
|
||||||
if lastJSError == nil:
|
if lastJSError == nil:
|
||||||
raise newException(ReraiseError, "no exception to reraise")
|
raise newException(ReraiseDefect, "no exception to reraise")
|
||||||
else:
|
else:
|
||||||
if excHandler == 0:
|
if excHandler == 0:
|
||||||
if isNimException():
|
if isNimException():
|
||||||
@@ -151,19 +151,19 @@ proc reraiseException() {.compilerproc, asmNoStackFrame.} =
|
|||||||
asm "throw lastJSError;"
|
asm "throw lastJSError;"
|
||||||
|
|
||||||
proc raiseOverflow {.exportc: "raiseOverflow", noreturn, compilerproc.} =
|
proc raiseOverflow {.exportc: "raiseOverflow", noreturn, compilerproc.} =
|
||||||
raise newException(OverflowError, "over- or underflow")
|
raise newException(OverflowDefect, "over- or underflow")
|
||||||
|
|
||||||
proc raiseDivByZero {.exportc: "raiseDivByZero", noreturn, compilerproc.} =
|
proc raiseDivByZero {.exportc: "raiseDivByZero", noreturn, compilerproc.} =
|
||||||
raise newException(DivByZeroError, "division by zero")
|
raise newException(DivByZeroDefect, "division by zero")
|
||||||
|
|
||||||
proc raiseRangeError() {.compilerproc, noreturn.} =
|
proc raiseRangeError() {.compilerproc, noreturn.} =
|
||||||
raise newException(RangeError, "value out of range")
|
raise newException(RangeDefect, "value out of range")
|
||||||
|
|
||||||
proc raiseIndexError(i, a, b: int) {.compilerproc, noreturn.} =
|
proc raiseIndexError(i, a, b: int) {.compilerproc, noreturn.} =
|
||||||
raise newException(IndexError, formatErrorIndexBound(int(i), int(a), int(b)))
|
raise newException(IndexDefect, formatErrorIndexBound(int(i), int(a), int(b)))
|
||||||
|
|
||||||
proc raiseFieldError(f: string) {.compilerproc, noreturn.} =
|
proc raiseFieldError(f: string) {.compilerproc, noreturn.} =
|
||||||
raise newException(FieldError, f)
|
raise newException(FieldDefect, f)
|
||||||
|
|
||||||
proc setConstr() {.varargs, asmNoStackFrame, compilerproc.} =
|
proc setConstr() {.varargs, asmNoStackFrame, compilerproc.} =
|
||||||
asm """
|
asm """
|
||||||
@@ -524,7 +524,7 @@ proc nimMax(a, b: int): int {.compilerproc.} = return if a >= b: a else: b
|
|||||||
|
|
||||||
proc chckNilDisp(p: pointer) {.compilerproc.} =
|
proc chckNilDisp(p: pointer) {.compilerproc.} =
|
||||||
if p == nil:
|
if p == nil:
|
||||||
sysFatal(NilAccessError, "cannot dispatch; dispatcher is nil")
|
sysFatal(NilAccessDefect, "cannot dispatch; dispatcher is nil")
|
||||||
|
|
||||||
include "system/hti"
|
include "system/hti"
|
||||||
|
|
||||||
@@ -663,7 +663,7 @@ proc chckObj(obj, subclass: PNimType) {.compilerproc.} =
|
|||||||
if x == subclass: return # optimized fast path
|
if x == subclass: return # optimized fast path
|
||||||
while x != subclass:
|
while x != subclass:
|
||||||
if x == nil:
|
if x == nil:
|
||||||
raise newException(ObjectConversionError, "invalid object conversion")
|
raise newException(ObjectConversionDefect, "invalid object conversion")
|
||||||
x = x.base
|
x = x.base
|
||||||
|
|
||||||
proc isObj(obj, subclass: PNimType): bool {.compilerproc.} =
|
proc isObj(obj, subclass: PNimType): bool {.compilerproc.} =
|
||||||
|
|||||||
@@ -191,4 +191,4 @@ proc isObj(obj: PNimType, subclass: cstring): bool {.compilerRtl, inl.} =
|
|||||||
|
|
||||||
proc chckObj(obj: PNimType, subclass: cstring) {.compilerRtl.} =
|
proc chckObj(obj: PNimType, subclass: cstring) {.compilerRtl.} =
|
||||||
# checks if obj is of type subclass:
|
# checks if obj is of type subclass:
|
||||||
if not isObj(obj, subclass): sysFatal(ObjectConversionError, "invalid object conversion")
|
if not isObj(obj, subclass): sysFatal(ObjectConversionDefect, "invalid object conversion")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
discard """
|
discard """
|
||||||
outputsub: '''ObjectAssignmentError'''
|
outputsub: '''ObjectAssignmentDefect'''
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
discard """
|
discard """
|
||||||
outputsub: '''ObjectAssignmentError'''
|
outputsub: '''ObjectAssignmentDefect'''
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -154,16 +154,16 @@ type
|
|||||||
x1: string
|
x1: string
|
||||||
case kind1: bool
|
case kind1: bool
|
||||||
of false: y1: string
|
of false: y1: string
|
||||||
of true:
|
of true:
|
||||||
y2: seq[string]
|
y2: seq[string]
|
||||||
case kind2: bool
|
case kind2: bool
|
||||||
of true: z1: string
|
of true: z1: string
|
||||||
of false:
|
of false:
|
||||||
z2: seq[string]
|
z2: seq[string]
|
||||||
flag: bool
|
flag: bool
|
||||||
x2: string
|
x2: string
|
||||||
|
|
||||||
proc test_myobject =
|
proc test_myobject =
|
||||||
var x: MyObject
|
var x: MyObject
|
||||||
x.x1 = "x1"
|
x.x1 = "x1"
|
||||||
x.x2 = "x2"
|
x.x2 = "x2"
|
||||||
@@ -183,7 +183,7 @@ proc test_myobject =
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
x.kind1 = x.flag # flag is not accesible
|
x.kind1 = x.flag # flag is not accesible
|
||||||
except FieldError:
|
except FieldDefect:
|
||||||
echo "prevented"
|
echo "prevented"
|
||||||
|
|
||||||
doAssert(x.x1 == "x1")
|
doAssert(x.x1 == "x1")
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ proc callC() = callA()
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
callC()
|
callC()
|
||||||
except AssertionError:
|
except AssertionDefect:
|
||||||
write(stdout, "assertion failure!")
|
write(stdout, "assertion failure!")
|
||||||
except:
|
except:
|
||||||
write(stdout, "unknown exception!")
|
write(stdout, "unknown exception!")
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ type
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
doAssert(false, "msg1") # doAssert test
|
doAssert(false, "msg1") # doAssert test
|
||||||
except AssertionError as e:
|
except AssertionDefect as e:
|
||||||
assert e.msg.endsWith "tassert2.nim(20, 11) `false` msg1"
|
assert e.msg.endsWith "tassert2.nim(20, 11) `false` msg1"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
assert false # assert test with no msg
|
assert false # assert test with no msg
|
||||||
except AssertionError as e:
|
except AssertionDefect as e:
|
||||||
assert e.msg.endsWith "tassert2.nim(25, 10) `false` "
|
assert e.msg.endsWith "tassert2.nim(25, 10) `false` "
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -31,13 +31,13 @@ try:
|
|||||||
doAssert(a+a==1) # assert test with Ast expression
|
doAssert(a+a==1) # assert test with Ast expression
|
||||||
# BUG: const folding would make "1+1==1" appear as `false` in
|
# BUG: const folding would make "1+1==1" appear as `false` in
|
||||||
# assert message
|
# assert message
|
||||||
except AssertionError as e:
|
except AssertionDefect as e:
|
||||||
assert e.msg.endsWith "`a + a == 1` "
|
assert e.msg.endsWith "`a + a == 1` "
|
||||||
|
|
||||||
try:
|
try:
|
||||||
let a = 1
|
let a = 1
|
||||||
doAssert a+a==1 # ditto with `doAssert` and no parens
|
doAssert a+a==1 # ditto with `doAssert` and no parens
|
||||||
except AssertionError as e:
|
except AssertionDefect as e:
|
||||||
assert e.msg.endsWith "`a + a == 1` "
|
assert e.msg.endsWith "`a + a == 1` "
|
||||||
|
|
||||||
proc fooStatic() =
|
proc fooStatic() =
|
||||||
@@ -91,14 +91,14 @@ block: ## checks for issue https://github.com/nim-lang/Nim/issues/8518
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
doAssert fun("foo1") == fun("foo2"), "mymsg"
|
doAssert fun("foo1") == fun("foo2"), "mymsg"
|
||||||
except AssertionError as e:
|
except AssertionDefect as e:
|
||||||
# used to expand out the template instantiaiton, sometimes filling hundreds of lines
|
# used to expand out the template instantiaiton, sometimes filling hundreds of lines
|
||||||
assert e.msg.endsWith ""
|
assert e.msg.endsWith ""
|
||||||
|
|
||||||
block: ## checks for issue https://github.com/nim-lang/Nim/issues/9301
|
block: ## checks for issue https://github.com/nim-lang/Nim/issues/9301
|
||||||
try:
|
try:
|
||||||
doAssert 1 + 1 == 3
|
doAssert 1 + 1 == 3
|
||||||
except AssertionError as e:
|
except AssertionDefect as e:
|
||||||
# used to const fold as false
|
# used to const fold as false
|
||||||
assert e.msg.endsWith "tassert2.nim(100, 14) `1 + 1 == 3` "
|
assert e.msg.endsWith "tassert2.nim(100, 14) `1 + 1 == 3` "
|
||||||
|
|
||||||
@@ -106,6 +106,6 @@ block: ## checks AST isn't transformed as it used to
|
|||||||
let a = 1
|
let a = 1
|
||||||
try:
|
try:
|
||||||
doAssert a > 1
|
doAssert a > 1
|
||||||
except AssertionError as e:
|
except AssertionDefect as e:
|
||||||
# used to rewrite as `1 < a`
|
# used to rewrite as `1 < a`
|
||||||
assert e.msg.endsWith "tassert2.nim(108, 14) `a > 1` "
|
assert e.msg.endsWith "tassert2.nim(108, 14) `a > 1` "
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ try:
|
|||||||
proc foo() =
|
proc foo() =
|
||||||
assert(false)
|
assert(false)
|
||||||
foo()
|
foo()
|
||||||
except AssertionError:
|
except AssertionDefect:
|
||||||
let e = getCurrentException()
|
let e = getCurrentException()
|
||||||
let trace = e.getStackTrace
|
let trace = e.getStackTrace
|
||||||
if tmatch(trace, expected): echo true else: echo "wrong trace:\n" & trace
|
if tmatch(trace, expected): echo true else: echo "wrong trace:\n" & trace
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import asyncdispatch, strutils
|
|||||||
|
|
||||||
proc foobar() {.async.} =
|
proc foobar() {.async.} =
|
||||||
if 5 == 5:
|
if 5 == 5:
|
||||||
raise newException(IndexError, "Test")
|
raise newException(IndexDefect, "Test")
|
||||||
|
|
||||||
proc catch() {.async.} =
|
proc catch() {.async.} =
|
||||||
# TODO: Create a test for when exceptions are not caught.
|
# TODO: Create a test for when exceptions are not caught.
|
||||||
@@ -25,26 +25,26 @@ proc catch() {.async.} =
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await foobar()
|
await foobar()
|
||||||
except IndexError:
|
except IndexDefect:
|
||||||
echo("Specific except")
|
echo("Specific except")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await foobar()
|
await foobar()
|
||||||
except OSError, FieldError, IndexError:
|
except OSError, FieldDefect, IndexDefect:
|
||||||
echo("Multiple idents in except")
|
echo("Multiple idents in except")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await foobar()
|
await foobar()
|
||||||
except OSError, FieldError:
|
except OSError, FieldDefect:
|
||||||
assert false
|
assert false
|
||||||
except IndexError:
|
except IndexDefect:
|
||||||
echo("Multiple except branches")
|
echo("Multiple except branches")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await foobar()
|
await foobar()
|
||||||
except IndexError:
|
except IndexDefect:
|
||||||
echo("Multiple except branches 2")
|
echo("Multiple except branches 2")
|
||||||
except OSError, FieldError:
|
except OSError, FieldDefect:
|
||||||
assert false
|
assert false
|
||||||
|
|
||||||
waitFor catch()
|
waitFor catch()
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ when defined(upcoming):
|
|||||||
poll()
|
poll()
|
||||||
|
|
||||||
proc eventTest5298() =
|
proc eventTest5298() =
|
||||||
# Event must raise `AssertionError` if event was unregistered twice.
|
# Event must raise `AssertionDefect` if event was unregistered twice.
|
||||||
# Issue #5298.
|
# Issue #5298.
|
||||||
let e = newAsyncEvent()
|
let e = newAsyncEvent()
|
||||||
var eventReceived = false
|
var eventReceived = false
|
||||||
@@ -57,7 +57,7 @@ when defined(upcoming):
|
|||||||
poll()
|
poll()
|
||||||
try:
|
try:
|
||||||
e.unregister()
|
e.unregister()
|
||||||
except AssertionError:
|
except AssertionDefect:
|
||||||
discard
|
discard
|
||||||
e.close()
|
e.close()
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import compiler/unittest_light
|
|||||||
|
|
||||||
proc testAssertEquals() =
|
proc testAssertEquals() =
|
||||||
assertEquals("foo", "foo")
|
assertEquals("foo", "foo")
|
||||||
doAssertRaises(AssertionError):
|
doAssertRaises(AssertionDefect):
|
||||||
assertEquals("foo", "foo ")
|
assertEquals("foo", "foo ")
|
||||||
|
|
||||||
proc testMismatch() =
|
proc testMismatch() =
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ proc getFirstValue[K,V](m : Map[K,V]): V =
|
|||||||
for i in m.valuesSeq:
|
for i in m.valuesSeq:
|
||||||
return i
|
return i
|
||||||
|
|
||||||
raise newException(RangeError, "no values")
|
raise newException(RangeDefect, "no values")
|
||||||
|
|
||||||
proc useConceptProcInGeneric[K, V](t: Table[K, V]): V =
|
proc useConceptProcInGeneric[K, V](t: Table[K, V]): V =
|
||||||
return t.getFirstValue
|
return t.getFirstValue
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ proc main() =
|
|||||||
try:
|
try:
|
||||||
echo "before"
|
echo "before"
|
||||||
raise newException(CatchableError, "foo")
|
raise newException(CatchableError, "foo")
|
||||||
except AssertionError:
|
except AssertionDefect:
|
||||||
echo "caught"
|
echo "caught"
|
||||||
echo "after"
|
echo "after"
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ proc mainB() =
|
|||||||
echo "before"
|
echo "before"
|
||||||
raise newException(CatchableError, "foo")
|
raise newException(CatchableError, "foo")
|
||||||
# except CatchableError: # would work
|
# except CatchableError: # would work
|
||||||
except AssertionError:
|
except AssertionDefect:
|
||||||
echo "caught"
|
echo "caught"
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ discard """
|
|||||||
cmd: "nim c --gc:arc --exceptions:goto --panics:off $file"
|
cmd: "nim c --gc:arc --exceptions:goto --panics:off $file"
|
||||||
output: '''prevented!
|
output: '''prevented!
|
||||||
caught
|
caught
|
||||||
AssertionError
|
AssertionDefect
|
||||||
900'''
|
900'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -30,18 +30,18 @@ proc main(i: int) =
|
|||||||
try:
|
try:
|
||||||
var objA = ObjA()
|
var objA = ObjA()
|
||||||
bplease(ObjB(objA))
|
bplease(ObjB(objA))
|
||||||
except ObjectConversionError:
|
except ObjectConversionDefect:
|
||||||
echo "prevented!"
|
echo "prevented!"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
takeRange(i)
|
takeRange(i)
|
||||||
except RangeError:
|
except RangeDefect:
|
||||||
echo "caught"
|
echo "caught"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
helper()
|
helper()
|
||||||
except AssertionError:
|
except AssertionDefect:
|
||||||
echo "AssertionError"
|
echo "AssertionDefect"
|
||||||
|
|
||||||
echo i * i
|
echo i * i
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
discard """
|
discard """
|
||||||
outputsub: "index 2 not in 0 .. 0 [IndexError]"
|
outputsub: "index 2 not in 0 .. 0 [IndexDefect]"
|
||||||
exitcode: 1
|
exitcode: 1
|
||||||
cmd: "nim c --gc:arc --exceptions:setjmp $file"
|
cmd: "nim c --gc:arc --exceptions:setjmp $file"
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
discard """
|
discard """
|
||||||
errormsg: "can raise an unlisted exception: ref FloatingPointError"
|
errormsg: "can raise an unlisted exception: ref FloatingPointDefect"
|
||||||
line: 10
|
line: 10
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ proc foo() {.raises: [].} =
|
|||||||
try:
|
try:
|
||||||
discard
|
discard
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise newException(FloatingPointError, "foo")
|
raise newException(FloatingPointDefect, "foo")
|
||||||
except Exception:
|
except Exception:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|||||||
@@ -89,10 +89,10 @@ block:
|
|||||||
result.add(1212)
|
result.add(1212)
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
raise newException(AssertionError, "a")
|
raise newException(AssertionDefect, "a")
|
||||||
finally:
|
finally:
|
||||||
result.add(42)
|
result.add(42)
|
||||||
except AssertionError:
|
except AssertionDefect:
|
||||||
result.add(99)
|
result.add(99)
|
||||||
finally:
|
finally:
|
||||||
result.add(10)
|
result.add(10)
|
||||||
@@ -104,7 +104,7 @@ block:
|
|||||||
result.add(-1)
|
result.add(-1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
result.add(-1)
|
result.add(-1)
|
||||||
except IndexError:
|
except IndexDefect:
|
||||||
result.add(2)
|
result.add(2)
|
||||||
except:
|
except:
|
||||||
result.add(3)
|
result.add(3)
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ discard """
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
raise newException(ValueError, "")
|
raise newException(ValueError, "")
|
||||||
except OverflowError:
|
except OverflowDefect:
|
||||||
echo("Error caught")
|
echo("Error caught")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
discard """
|
discard """
|
||||||
outputsub: "Error: unhandled exception: FPU operation caused an overflow [FloatOverflowError]"
|
outputsub: "Error: unhandled exception: FPU operation caused an overflow [FloatOverflowDefect]"
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
# Test new floating point exceptions
|
# Test new floating point exceptions
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
discard """
|
discard """
|
||||||
outputsub: "Error: unhandled exception: FPU operation caused a NaN result [FloatInvalidOpError]"
|
outputsub: "Error: unhandled exception: FPU operation caused a NaN result [FloatInvalidOpDefect]"
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
# Test new floating point exceptions
|
# Test new floating point exceptions
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
proc foo =
|
proc foo =
|
||||||
var x: seq[int]
|
var x: seq[int]
|
||||||
doAssertRaises(IndexError):
|
doAssertRaises(IndexDefect):
|
||||||
inc x[0]
|
inc x[0]
|
||||||
|
|
||||||
foo()
|
foo()
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ var obj = X(f0: "foo", f1: C, f3: 3.14)
|
|||||||
block:
|
block:
|
||||||
echo obj.f0
|
echo obj.f0
|
||||||
echo obj.f1
|
echo obj.f1
|
||||||
doAssertRaises(FieldError): echo obj.f2
|
doAssertRaises(FieldDefect): echo obj.f2
|
||||||
echo obj.f3
|
echo obj.f3
|
||||||
|
|
||||||
block:
|
block:
|
||||||
@@ -32,7 +32,7 @@ block:
|
|||||||
echo a0[]
|
echo a0[]
|
||||||
# let a1 = unsafeAddr(obj.f1)
|
# let a1 = unsafeAddr(obj.f1)
|
||||||
# echo a1[]
|
# echo a1[]
|
||||||
doAssertRaises(FieldError):
|
doAssertRaises(FieldDefect):
|
||||||
let a2 = addr(obj.f2)
|
let a2 = addr(obj.f2)
|
||||||
echo a2[]
|
echo a2[]
|
||||||
let a3 = addr(obj.f3)
|
let a3 = addr(obj.f3)
|
||||||
|
|||||||
@@ -251,8 +251,8 @@ proc parse_parameter(quit_on_failure: bool, param, value: string,
|
|||||||
case param_kind:
|
case param_kind:
|
||||||
of PK_INT:
|
of PK_INT:
|
||||||
try: result.int_val = value.parseInt
|
try: result.int_val = value.parseInt
|
||||||
except OverflowError:
|
except OverflowDefect:
|
||||||
raise_or_quit(OverflowError, ("parameter $1 requires an " &
|
raise_or_quit(OverflowDefect, ("parameter $1 requires an " &
|
||||||
"integer, but $2 is too large to fit into one") % [param,
|
"integer, but $2 is too large to fit into one") % [param,
|
||||||
escape(value)])
|
escape(value)])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ type
|
|||||||
|
|
||||||
proc toNumber[T: int|uint|int64|uint64](v: ResultValue): T =
|
proc toNumber[T: int|uint|int64|uint64](v: ResultValue): T =
|
||||||
if v < low(T) or v > high(T):
|
if v < low(T) or v > high(T):
|
||||||
raise newException(RangeError, "protocol error")
|
raise newException(RangeDefect, "protocol error")
|
||||||
return T(v)
|
return T(v)
|
||||||
|
|
||||||
#proc toNumber[T](v: int32): T =
|
#proc toNumber[T](v: int32): T =
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
discard """
|
discard """
|
||||||
outputsub: '''Error: unhandled exception: cannot dispatch; dispatcher is nil [NilAccessError]'''
|
outputsub: '''Error: unhandled exception: cannot dispatch; dispatcher is nil [NilAccessDefect]'''
|
||||||
exitcode: 1
|
exitcode: 1
|
||||||
"""
|
"""
|
||||||
# bug #5599
|
# bug #5599
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ var x: range[1..10] = 10
|
|||||||
try:
|
try:
|
||||||
x += 1
|
x += 1
|
||||||
echo x
|
echo x
|
||||||
except OverflowError, RangeError:
|
except OverflowDefect, RangeDefect:
|
||||||
expected += 1
|
expected += 1
|
||||||
echo x
|
echo x
|
||||||
|
|
||||||
try:
|
try:
|
||||||
inc x
|
inc x
|
||||||
echo x
|
echo x
|
||||||
except OverflowError, RangeError:
|
except OverflowDefect, RangeDefect:
|
||||||
expected += 1
|
expected += 1
|
||||||
echo x
|
echo x
|
||||||
|
|
||||||
@@ -29,14 +29,14 @@ x = 1
|
|||||||
try:
|
try:
|
||||||
x -= 1
|
x -= 1
|
||||||
echo x
|
echo x
|
||||||
except OverflowError, RangeError:
|
except OverflowDefect, RangeDefect:
|
||||||
expected += 1
|
expected += 1
|
||||||
echo x
|
echo x
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dec x
|
dec x
|
||||||
echo x
|
echo x
|
||||||
except OverflowError, RangeError:
|
except OverflowDefect, RangeDefect:
|
||||||
expected += 1
|
expected += 1
|
||||||
echo x
|
echo x
|
||||||
|
|
||||||
|
|||||||
@@ -2,25 +2,25 @@ discard """
|
|||||||
action: run
|
action: run
|
||||||
"""
|
"""
|
||||||
|
|
||||||
doAssertRaises(OverflowError): discard low(int8) - 1'i8
|
doAssertRaises(OverflowDefect): discard low(int8) - 1'i8
|
||||||
doAssertRaises(OverflowError): discard high(int8) + 1'i8
|
doAssertRaises(OverflowDefect): discard high(int8) + 1'i8
|
||||||
doAssertRaises(OverflowError): discard abs(low(int8))
|
doAssertRaises(OverflowDefect): discard abs(low(int8))
|
||||||
doAssertRaises(DivByZeroError): discard 1 mod 0
|
doAssertRaises(DivByZeroDefect): discard 1 mod 0
|
||||||
doAssertRaises(DivByZeroError): discard 1 div 0
|
doAssertRaises(DivByZeroDefect): discard 1 div 0
|
||||||
doAssertRaises(OverflowError): discard low(int8) div -1'i8
|
doAssertRaises(OverflowDefect): discard low(int8) div -1'i8
|
||||||
|
|
||||||
doAssertRaises(OverflowError): discard -low(int64)
|
doAssertRaises(OverflowDefect): discard -low(int64)
|
||||||
doAssertRaises(OverflowError): discard low(int64) - 1'i64
|
doAssertRaises(OverflowDefect): discard low(int64) - 1'i64
|
||||||
doAssertRaises(OverflowError): discard high(int64) + 1'i64
|
doAssertRaises(OverflowDefect): discard high(int64) + 1'i64
|
||||||
|
|
||||||
type E = enum eA, eB
|
type E = enum eA, eB
|
||||||
doAssertRaises(OverflowError): discard eA.pred
|
doAssertRaises(OverflowDefect): discard eA.pred
|
||||||
doAssertRaises(OverflowError): discard eB.succ
|
doAssertRaises(OverflowDefect): discard eB.succ
|
||||||
|
|
||||||
doAssertRaises(OverflowError): discard low(int8) * -1
|
doAssertRaises(OverflowDefect): discard low(int8) * -1
|
||||||
doAssertRaises(OverflowError): discard low(int64) * -1
|
doAssertRaises(OverflowDefect): discard low(int64) * -1
|
||||||
doAssertRaises(OverflowError): discard high(int8) * 2
|
doAssertRaises(OverflowDefect): discard high(int8) * 2
|
||||||
doAssertRaises(OverflowError): discard high(int64) * 2
|
doAssertRaises(OverflowDefect): discard high(int64) * 2
|
||||||
|
|
||||||
doAssert abs(-1) == 1
|
doAssert abs(-1) == 1
|
||||||
doAssert 2 div 2 == 1
|
doAssert 2 div 2 == 1
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
block: # bug #2427
|
block: # bug #2427
|
||||||
var x = 0'u8
|
var x = 0'u8
|
||||||
dec x # OverflowError
|
dec x # OverflowDefect
|
||||||
x -= 1 # OverflowError
|
x -= 1 # OverflowDefect
|
||||||
x = x - 1 # No error
|
x = x - 1 # No error
|
||||||
|
|
||||||
doAssert(x == 253'u8)
|
doAssert(x == 253'u8)
|
||||||
|
|||||||
@@ -179,13 +179,13 @@ for i in list4.low .. list4.high:
|
|||||||
echo(list4[i])
|
echo(list4[i])
|
||||||
|
|
||||||
var list5: seq[int] = @[]
|
var list5: seq[int] = @[]
|
||||||
doAssertRaises(IndexError):
|
doAssertRaises(IndexDefect):
|
||||||
list5[0] = 1
|
list5[0] = 1
|
||||||
|
|
||||||
list5.add(1)
|
list5.add(1)
|
||||||
|
|
||||||
assert list5[0] == 1
|
assert list5[0] == 1
|
||||||
doAssertRaises(IndexError):
|
doAssertRaises(IndexDefect):
|
||||||
echo list5[42]
|
echo list5[42]
|
||||||
|
|
||||||
# -- Errata: var list: seq[int]; echo(list[0]). This now creates an exception,
|
# -- Errata: var list: seq[int]; echo(list[0]). This now creates an exception,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ block:
|
|||||||
assert obj.contents == "Hello"
|
assert obj.contents == "Hello"
|
||||||
|
|
||||||
var obj2 = Box(empty: true)
|
var obj2 = Box(empty: true)
|
||||||
doAssertRaises(FieldError):
|
doAssertRaises(FieldDefect):
|
||||||
echo(obj2.contents)
|
echo(obj2.contents)
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
discard """
|
discard """
|
||||||
outputsub: '''ObjectAssignmentError'''
|
outputsub: '''ObjectAssignmentDefect'''
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ var
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
writeLine(stdout, b - a)
|
writeLine(stdout, b - a)
|
||||||
except OverflowError:
|
except OverflowDefect:
|
||||||
overflowDetected = true
|
overflowDetected = true
|
||||||
|
|
||||||
{.pop.} # overflow check
|
{.pop.} # overflow check
|
||||||
@@ -33,7 +33,7 @@ block: # Overflow checks in a proc
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
foo()
|
foo()
|
||||||
except OverflowError:
|
except OverflowDefect:
|
||||||
overflowDetected = true
|
overflowDetected = true
|
||||||
|
|
||||||
doAssert(overflowDetected)
|
doAssert(overflowDetected)
|
||||||
@@ -53,7 +53,7 @@ block: # Overflow checks in a forward declared proc
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
foo()
|
foo()
|
||||||
except OverflowError:
|
except OverflowDefect:
|
||||||
overflowDetected = true
|
overflowDetected = true
|
||||||
|
|
||||||
doAssert(overflowDetected)
|
doAssert(overflowDetected)
|
||||||
@@ -73,7 +73,7 @@ block: # Overflow checks doesn't affect fwd declaration
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
foo()
|
foo()
|
||||||
except OverflowError:
|
except OverflowDefect:
|
||||||
overflowDetected = true
|
overflowDetected = true
|
||||||
|
|
||||||
doAssert(not overflowDetected)
|
doAssert(not overflowDetected)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
discard """
|
discard """
|
||||||
outputsub: "Error: unhandled exception: over- or underflow [OverflowError]"
|
outputsub: "Error: unhandled exception: over- or underflow [OverflowDefect]"
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
var a : int32 = 2147483647
|
var a : int32 = 2147483647
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
discard """
|
discard """
|
||||||
outputsub: "value out of range: 50 notin 0 .. 40 [RangeError]"
|
outputsub: "value out of range: 50 notin 0 .. 40 [RangeDefect]"
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
discard """
|
discard """
|
||||||
outputsub: "value out of range: 50 notin 0 .. 40 [RangeError]"
|
outputsub: "value out of range: 50 notin 0 .. 40 [RangeDefect]"
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ var
|
|||||||
try:
|
try:
|
||||||
var
|
var
|
||||||
r = initRational(1, 0) # this fails - no zero denominator
|
r = initRational(1, 0) # this fails - no zero denominator
|
||||||
except AssertionError:
|
except AssertionDefect:
|
||||||
echo "true"
|
echo "true"
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ suite "replace":
|
|||||||
check("123".replace(re"(?<foo>\d)(\d)", "${foo}$#$#") == "1123")
|
check("123".replace(re"(?<foo>\d)(\d)", "${foo}$#$#") == "1123")
|
||||||
|
|
||||||
test "replacing missing captures should throw instead of segfaulting":
|
test "replacing missing captures should throw instead of segfaulting":
|
||||||
expect IndexError: discard "ab".replace(re"(a)|(b)", "$1$2")
|
expect IndexDefect: discard "ab".replace(re"(a)|(b)", "$1$2")
|
||||||
expect IndexError: discard "b".replace(re"(a)?(b)", "$1$2")
|
expect IndexDefect: discard "b".replace(re"(a)?(b)", "$1$2")
|
||||||
expect KeyError: discard "b".replace(re"(a)?", "${foo}")
|
expect KeyError: discard "b".replace(re"(a)?", "${foo}")
|
||||||
expect KeyError: discard "b".replace(re"(?<foo>a)?", "${foo}")
|
expect KeyError: discard "b".replace(re"(?<foo>a)?", "${foo}")
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ block: # not ready for vm because exception is compile error
|
|||||||
var i = 32
|
var i = 32
|
||||||
v.setBit(i)
|
v.setBit(i)
|
||||||
doAssert false
|
doAssert false
|
||||||
except RangeError:
|
except RangeDefect:
|
||||||
discard
|
discard
|
||||||
except:
|
except:
|
||||||
doAssert false
|
doAssert false
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ block tcount:
|
|||||||
|
|
||||||
# bubble sort
|
# bubble sort
|
||||||
for i in low(arr)..high(arr):
|
for i in low(arr)..high(arr):
|
||||||
for j in i+1..high(arr): # Error: unhandled exception: value out of range: 5 [RangeError]
|
for j in i+1..high(arr): # Error: unhandled exception: value out of range: 5 [RangeDefect]
|
||||||
if arr[i] > arr[j]:
|
if arr[i] > arr[j]:
|
||||||
let tmp = arr[i]
|
let tmp = arr[i]
|
||||||
arr[i] = arr[j]
|
arr[i] = arr[j]
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ block tsegfaults:
|
|||||||
raise newException(ValueError, "not a crash")
|
raise newException(ValueError, "not a crash")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
discard
|
discard
|
||||||
except NilAccessError:
|
except NilAccessDefect:
|
||||||
echo "caught a crash!"
|
echo "caught a crash!"
|
||||||
for i in 0..5:
|
for i in 0..5:
|
||||||
main()
|
main()
|
||||||
@@ -212,7 +212,7 @@ block tsplit2:
|
|||||||
try:
|
try:
|
||||||
discard "hello".split("")
|
discard "hello".split("")
|
||||||
echo "false"
|
echo "false"
|
||||||
except AssertionError:
|
except AssertionDefect:
|
||||||
echo "true"
|
echo "true"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ proc test_string_slice() =
|
|||||||
doAssert s == "ab1234567890cdefghijklmnopqrstuvwxyz"
|
doAssert s == "ab1234567890cdefghijklmnopqrstuvwxyz"
|
||||||
|
|
||||||
# bug #6223
|
# bug #6223
|
||||||
doAssertRaises(IndexError):
|
doAssertRaises(IndexDefect):
|
||||||
discard s[0..999]
|
discard s[0..999]
|
||||||
|
|
||||||
echo("OK")
|
echo("OK")
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import macros
|
|||||||
template rejectParse(e) =
|
template rejectParse(e) =
|
||||||
try:
|
try:
|
||||||
discard e
|
discard e
|
||||||
raise newException(AssertionError, "This was supposed to fail: $#!" % astToStr(e))
|
raise newException(AssertionDefect, "This was supposed to fail: $#!" % astToStr(e))
|
||||||
except ValueError: discard
|
except ValueError: discard
|
||||||
|
|
||||||
proc testStrip() =
|
proc testStrip() =
|
||||||
|
|||||||
@@ -626,8 +626,8 @@ suite "ttimes":
|
|||||||
doAssert a.month.Month == cast[Month](0)
|
doAssert a.month.Month == cast[Month](0)
|
||||||
doAssert a.monthday == 0
|
doAssert a.monthday == 0
|
||||||
|
|
||||||
doAssertRaises(AssertionError): discard getDayOfWeek(a.monthday, a.month, a.year)
|
doAssertRaises(AssertionDefect): discard getDayOfWeek(a.monthday, a.month, a.year)
|
||||||
doAssertRaises(AssertionError): discard a.toTime
|
doAssertRaises(AssertionDefect): discard a.toTime
|
||||||
|
|
||||||
test "inX procs":
|
test "inX procs":
|
||||||
doAssert initDuration(seconds = 1).inSeconds == 1
|
doAssert initDuration(seconds = 1).inSeconds == 1
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ proc defectiveRobot() =
|
|||||||
of 3: raise newException(IOError, "I can't do that Dave.")
|
of 3: raise newException(IOError, "I can't do that Dave.")
|
||||||
else: assert 2 + 2 == 5
|
else: assert 2 + 2 == 5
|
||||||
test "unittest expect":
|
test "unittest expect":
|
||||||
expect IOError, OSError, ValueError, AssertionError:
|
expect IOError, OSError, ValueError, AssertionDefect:
|
||||||
defectiveRobot()
|
defectiveRobot()
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ proc main() =
|
|||||||
# shows that checkNotZero won't be called if a nil is found earlier in chain
|
# shows that checkNotZero won't be called if a nil is found earlier in chain
|
||||||
doAssert ?.a.x1.checkNotZero == 0.0
|
doAssert ?.a.x1.checkNotZero == 0.0
|
||||||
|
|
||||||
# checks that a chain without nil but with an empty seq still throws IndexError
|
# checks that a chain without nil but with an empty seq still throws IndexDefect
|
||||||
doAssertRaises(IndexError): discard ?.a2.x8[3]
|
doAssertRaises(IndexDefect): discard ?.a2.x8[3]
|
||||||
|
|
||||||
# make sure no double evaluation bug
|
# make sure no double evaluation bug
|
||||||
doAssert witness == 0
|
doAssert witness == 0
|
||||||
|
|||||||
@@ -81,13 +81,13 @@ foo(toOpenArray(seqq, 1, 3))
|
|||||||
# empty openArray issue #7904
|
# empty openArray issue #7904
|
||||||
foo(toOpenArray(seqq, 0, -1))
|
foo(toOpenArray(seqq, 0, -1))
|
||||||
foo(toOpenArray(seqq, 1, 0))
|
foo(toOpenArray(seqq, 1, 0))
|
||||||
doAssertRaises(IndexError):
|
doAssertRaises(IndexDefect):
|
||||||
foo(toOpenArray(seqq, 0, -2))
|
foo(toOpenArray(seqq, 0, -2))
|
||||||
|
|
||||||
foo(toOpenArray(arr, 9, 8))
|
foo(toOpenArray(arr, 9, 8))
|
||||||
foo(toOpenArray(arr, 0, -1))
|
foo(toOpenArray(arr, 0, -1))
|
||||||
foo(toOpenArray(arr, 1, 0))
|
foo(toOpenArray(arr, 1, 0))
|
||||||
doAssertRaises(IndexError):
|
doAssertRaises(IndexDefect):
|
||||||
foo(toOpenArray(arr, 10, 8))
|
foo(toOpenArray(arr, 10, 8))
|
||||||
|
|
||||||
# test openArray of openArray
|
# test openArray of openArray
|
||||||
@@ -106,11 +106,11 @@ var arrNeg: array[-3 .. -1, int] = [1, 2, 3]
|
|||||||
foo(toOpenArray(arrNeg, -3, -1))
|
foo(toOpenArray(arrNeg, -3, -1))
|
||||||
foo(toOpenArray(arrNeg, 0, -1))
|
foo(toOpenArray(arrNeg, 0, -1))
|
||||||
foo(toOpenArray(arrNeg, -3, -4))
|
foo(toOpenArray(arrNeg, -3, -4))
|
||||||
doAssertRaises(IndexError):
|
doAssertRaises(IndexDefect):
|
||||||
foo(toOpenArray(arrNeg, -4, -1))
|
foo(toOpenArray(arrNeg, -4, -1))
|
||||||
doAssertRaises(IndexError):
|
doAssertRaises(IndexDefect):
|
||||||
foo(toOpenArray(arrNeg, -1, 0))
|
foo(toOpenArray(arrNeg, -1, 0))
|
||||||
doAssertRaises(IndexError):
|
doAssertRaises(IndexDefect):
|
||||||
foo(toOpenArray(arrNeg, -1, -3))
|
foo(toOpenArray(arrNeg, -1, -3))
|
||||||
doAssertRaises(Exception):
|
doAssertRaises(Exception):
|
||||||
raise newException(Exception, "foo")
|
raise newException(Exception, "foo")
|
||||||
@@ -118,9 +118,9 @@ doAssertRaises(Exception):
|
|||||||
block:
|
block:
|
||||||
var didThrow = false
|
var didThrow = false
|
||||||
try:
|
try:
|
||||||
doAssertRaises(IndexError): # should fail since it's wrong exception
|
doAssertRaises(IndexDefect): # should fail since it's wrong exception
|
||||||
raise newException(FieldError, "foo")
|
raise newException(FieldDefect, "foo")
|
||||||
except AssertionError:
|
except AssertionDefect:
|
||||||
# ok, throwing was correct behavior
|
# ok, throwing was correct behavior
|
||||||
didThrow = true
|
didThrow = true
|
||||||
doAssert didThrow
|
doAssert didThrow
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
discard """
|
discard """
|
||||||
targets: "c cpp"
|
targets: "c cpp"
|
||||||
outputsub: '''ObjectAssignmentError'''
|
outputsub: '''ObjectAssignmentDefect'''
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
discard """
|
discard """
|
||||||
targets: "c cpp"
|
targets: "c cpp"
|
||||||
outputsub: '''ObjectAssignmentError'''
|
outputsub: '''ObjectAssignmentDefect'''
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
discard """
|
discard """
|
||||||
targets: "c cpp"
|
targets: "c cpp"
|
||||||
outputsub: '''ObjectAssignmentError'''
|
outputsub: '''ObjectAssignmentDefect'''
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user