From 220b45048983998675df761d4f33cd31128f10d5 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 26 Apr 2023 22:32:10 +0200 Subject: fixes #21245; warn about destructors that can raise (#21726) * fixes #21245; warn about destructors that can raise * doc update * progress * typo --- compiler/sempass2.nim | 3 ++- compiler/semstmts.nim | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'compiler') 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 -- cgit 1.4.1-2-gfad0