Skip to content

Commit

Permalink
Produce an error when the result variable is used in void async procs (
Browse files Browse the repository at this point in the history
  • Loading branch information
zah authored Aug 5, 2020
1 parent 73de13c commit 0d4d000
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion chronos/asyncmacro2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,15 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
# -> complete(retFuture, result)
var iteratorNameSym = genSym(nskIterator, $prcName)
var procBody = prc.body.processBody(retFutureSym, subtypeIsVoid,
futureVarIdents)
futureVarIdents)
# don't do anything with forward bodies (empty)
if procBody.kind != nnkEmpty:
if subtypeIsVoid:
let resultTemplate = quote do:
template result: auto {.used.} =
{.fatal: "You should not reference the `result` variable inside a void async proc".}
procBody = newStmtList(resultTemplate, procBody)

# fix #13899, `defer` should not escape its original scope
procBody = newStmtList(newTree(nnkBlockStmt, newEmptyNode(), procBody))

Expand Down

0 comments on commit 0d4d000

Please sign in to comment.