From e502afe24cffce2a56b858e1596a2b311a89b127 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 11 Jan 2024 14:47:33 +0800 Subject: [PATCH] fixes #23129; fixes generated hooks raise unlisted Exception, which never raise (#23195) fixes #23129 (cherry picked from commit 62c5b8b2873caac3e56d15738f503e953840e6ca) --- compiler/liftdestructors.nim | 7 ++++++- tests/effects/thooks.nim | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/effects/thooks.nim diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index 6bc1280762570..bdc44358aa501 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -1165,7 +1165,12 @@ proc produceSym(g: ModuleGraph; c: PContext; typ: PType; kind: TTypeAttachedOp; # bug #19205: Do not forget to also copy the hidden type field: genTypeFieldCopy(a, typ, result.ast[bodyPos], d, src) - if not a.canRaise: incl result.flags, sfNeverRaises + if not a.canRaise: + incl result.flags, sfNeverRaises + result.ast[pragmasPos] = newNodeI(nkPragma, info) + result.ast[pragmasPos].add newTree(nkExprColonExpr, + newIdentNode(g.cache.getIdent("raises"), info), newNodeI(nkBracket, info)) + completePartialOp(g, idgen.module, typ, kind, result) diff --git a/tests/effects/thooks.nim b/tests/effects/thooks.nim new file mode 100644 index 0000000000000..23cc005cd155f --- /dev/null +++ b/tests/effects/thooks.nim @@ -0,0 +1,16 @@ +discard """ + matrix: "--warningAsError:Effect" +""" + +import std/isolation + +# bug #23129 +type + Thing = object + x: string + +proc send(x: string) = + let wrapper = Thing(x: x) + discard isolate(wrapper) + +send("la") \ No newline at end of file