summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2023-04-26 22:32:10 +0200
committerGitHub <noreply@github.com>2023-04-26 22:32:10 +0200
commit220b45048983998675df761d4f33cd31128f10d5 (patch)
treeddd2f63e18137db689f88ee814d6d2cf209ac01d /compiler
parent8f79a124c96947283deecb137b7849557ae47f2f (diff)
downloadNim-220b45048983998675df761d4f33cd31128f10d5.tar.gz
fixes #21245; warn about destructors that can raise (#21726)
* fixes #21245; warn about destructors that can raise

* doc update

* progress

* typo
Diffstat (limited to 'compiler')
-rw-r--r--compiler/sempass2.nim3
-rw-r--r--compiler/semstmts.nim5
2 files changed, 7 insertions, 1 deletions
diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim
index ce4febd3f..f0e55887c 100644
--- a/compiler/sempass2.nim
+++ b/compiler/sempass2.nim
@@ -1499,7 +1499,8 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
   let p = s.ast[pragmasPos]
   let raisesSpec = effectSpec(p, wRaises)
   if not isNil(raisesSpec):
-    checkRaisesSpec(g, false, raisesSpec, t.exc, "can raise an unlisted exception: ",
+    let useWarning = s.name.s == "=destroy"
+    checkRaisesSpec(g, useWarning, raisesSpec, t.exc, "can raise an unlisted exception: ",
                     hints=on, subtypeRelation, hintsArg=s.ast[0])
     # after the check, use the formal spec:
     effects[exceptionEffects] = raisesSpec
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index d493364ea..43d22bc55 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -1857,6 +1857,11 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
   case name
   of "=destroy":
     bindTypeHook(c, s, n, attachedDestructor)
+    if s.ast != nil:
+      if s.ast[pragmasPos].kind == nkEmpty:
+        s.ast[pragmasPos] = newNodeI(nkPragma, s.info)
+      s.ast[pragmasPos].add newTree(nkExprColonExpr,
+          newIdentNode(c.cache.getIdent("raises"),  s.info), newNodeI(nkBracket, s.info))
   of "deepcopy", "=deepcopy":
     if s.typ.len == 2 and
         s.typ[1].skipTypes(abstractInst).kind in {tyRef, tyPtr} and