mirror of
https://github.com/logos-storage/nim-chronos.git
synced 2026-01-07 16:03:09 +00:00
Produce an error when the result variable is used in void async procs (#117)
This commit is contained in:
parent
73de13ca7a
commit
0d4d0002b0
@ -200,9 +200,15 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
|
|||||||
# -> complete(retFuture, result)
|
# -> complete(retFuture, result)
|
||||||
var iteratorNameSym = genSym(nskIterator, $prcName)
|
var iteratorNameSym = genSym(nskIterator, $prcName)
|
||||||
var procBody = prc.body.processBody(retFutureSym, subtypeIsVoid,
|
var procBody = prc.body.processBody(retFutureSym, subtypeIsVoid,
|
||||||
futureVarIdents)
|
futureVarIdents)
|
||||||
# don't do anything with forward bodies (empty)
|
# don't do anything with forward bodies (empty)
|
||||||
if procBody.kind != nnkEmpty:
|
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
|
# fix #13899, `defer` should not escape its original scope
|
||||||
procBody = newStmtList(newTree(nnkBlockStmt, newEmptyNode(), procBody))
|
procBody = newStmtList(newTree(nnkBlockStmt, newEmptyNode(), procBody))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user