Skip to content

Commit

Permalink
match exact type in result assignment helper
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed May 11, 2023
1 parent e4145ec commit 59b440f
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions chronos/asyncmacro2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
raiseAssert("Unhandled async return type: " & $prc.kind)

let subtypeIsVoid = baseType.eqIdent("void")
let returnTypeIsResult =
returnType.kind == nnkBracketExpr and baseType.kind == nnkBracketExpr and
(baseType[0].eqIdent("Result") or baseType[0].eqIdent("results.Result"))

if prc.kind in {nnkProcDef, nnkLambda, nnkMethodDef, nnkDo}:
let
Expand Down Expand Up @@ -150,12 +147,12 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
# fix #13899, `defer` should not escape its original scope
procBody = newStmtList(newTree(nnkBlockStmt, newEmptyNode(), procBody))

if returnTypeIsResult:
# Support `let x = ? await ...`, but only if `Result` exists as a symbol
let ar = ident "assignResult?"
procBody.insert 0, quote do:
template `ar`(v: Result) =
`internalFutureSym`.complete(v)
# Support `let x = ? await ...`, but only if `Result` exists as a symbol
let assignResult = ident "assignResult?"
procBody.insert 0, quote do:
when declared(Result):
template `assignResult`(v: `baseType`) =
`internalFutureSym`.complete(v)

if not subtypeIsVoid:
procBody.insert(0, newNimNode(nnkPragma).add(newIdentNode("push"),
Expand Down

0 comments on commit 59b440f

Please sign in to comment.