Fix async macro "CannotRaise" warnings in nim >1.2 (#332)

This commit is contained in:
Tanguy 2022-12-01 11:36:14 +01:00 committed by GitHub
parent 189f6e390c
commit 75d030ff71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 17 deletions

View File

@ -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