From 59b440f6e4b5fe30104618f7d41e7a3d1cfdd163 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 11 May 2023 18:43:39 +0200 Subject: [PATCH] match exact type in result assignment helper --- chronos/asyncmacro2.nim | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/chronos/asyncmacro2.nim b/chronos/asyncmacro2.nim index 863611026..ea398b837 100644 --- a/chronos/asyncmacro2.nim +++ b/chronos/asyncmacro2.nim @@ -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 @@ -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"),