do not track 'raise Defect' in the .raises: [] clause anymore (#14298)

* do not track 'raise Defect' in the .raises: [] clause anymore

* --panics:on maps 'raise Defect' to an unrecoverable fatal error

* make tests green again

* update the documentation too
This commit is contained in:
Andreas Rumpf 2020-05-11 16:25:56 +02:00 • committed by GitHub
commit 03c146cd93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 74 additions and 8 deletions

View file

@ -4338,6 +4338,28 @@ Rules 1-2 ensure the following works:
So in many cases a callback does not cause the compiler to be overly
conservative in its effect analysis.
Exceptions inheriting from ``system.Defect`` are not tracked with
the ``.raises: []`` exception tracking mechanism. This is more consistent with the
built-in operations. The following code is valid::
.. code-block:: nim
proc mydiv(a, b): int {.raises: [].} =
a div b # can raise an DivByZeroDefect
And so is::
.. code-block:: nim
proc mydiv(a, b): int {.raises: [].} =
if b == 0: raise newException(DivByZeroDefect, "division by zero")
else: result = a div b
The reason for this is that ``DivByZeroDefect`` inherits from ``Defect`` and
with ``--panics:on`` Defects become unrecoverable errors.
(Since version 1.4 of the language.)
Tag tracking
------------