From 75d030ff71264513fb9701c75a326cd36fcb4692 Mon Sep 17 00:00:00 2001 From: Tanguy Date: Thu, 1 Dec 2022 11:36:14 +0100 Subject: [PATCH] Fix async macro "CannotRaise" warnings in nim >1.2 (#332) --- chronos/asyncmacro2.nim | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/chronos/asyncmacro2.nim b/chronos/asyncmacro2.nim index 7439c3b..22e5f64 100644 --- a/chronos/asyncmacro2.nim +++ b/chronos/asyncmacro2.nim @@ -181,23 +181,16 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} = # against the spirit of the raises annotation - one should investigate # here the possibility of transporting more specific error types here # for example by casting exceptions coming out of `await`.. - when defined(chronosStrictException): - closureIterator.addPragma(nnkExprColonExpr.newTree( - newIdentNode("raises"), - nnkBracket.newTree( - newIdentNode("Defect"), - newIdentNode("CatchableError") - ) - )) - else: - closureIterator.addPragma(nnkExprColonExpr.newTree( - newIdentNode("raises"), - nnkBracket.newTree( - newIdentNode("Defect"), - newIdentNode("CatchableError"), - newIdentNode("Exception") # Allow exception effects - ) - )) + let raises = nnkBracket.newTree() + raises.add(newIdentNode("CatchableError")) + when not defined(chronosStrictException): + raises.add(newIdentNode("Exception")) + when (NimMajor, NimMinor) < (1, 4): + raises.add(newIdentNode("Defect")) + closureIterator.addPragma(nnkExprColonExpr.newTree( + newIdentNode("raises"), + raises + )) # If proc has an explicit gcsafe pragma, we add it to iterator as well. if prc.pragma.findChild(it.kind in {nnkSym, nnkIdent} and