summary refs log tree commit diff stats
path: root/lib/pure/asyncmacro.nim
diff options
context:
space:
mode:
authorJake Leahy <jake@leahy.dev>2023-05-25 15:08:36 +1000
committerGitHub <noreply@github.com>2023-05-25 07:08:36 +0200
commita8718d8a9e1aba7df55b1a3df1ce48a3f4f62bff (patch)
treecfb69c12c0ffa5fe2e57178ac2d97c3fae8c5626 /lib/pure/asyncmacro.nim
parentb7925bf5c937bf3cb71290949d279872c4d0cb8e (diff)
downloadNim-a8718d8a9e1aba7df55b1a3df1ce48a3f4f62bff.tar.gz
Fix const in async regression (#21898)
* Add test case for a const being used inside an async proc

* Use `typeof` to get the type of the block instead of overloaded templates

This removes the problem with the symbol having different types

I am unsure why I didn't use this in the first place. IIRC I had problems with `typeof` when I first tried to use it in the original implementation
Diffstat (limited to 'lib/pure/asyncmacro.nim')
-rw-r--r--lib/pure/asyncmacro.nim12
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim
index d80a47101..e41568b8c 100644
--- a/lib/pure/asyncmacro.nim
+++ b/lib/pure/asyncmacro.nim
@@ -221,13 +221,11 @@ proc asyncSingleProc(prc: NimNode): NimNode =
     procBody = newStmtList()
     let resultIdent = ident"result"
     procBody.add quote do:
-      template nimAsyncDispatchSetResult(x: `subRetType`) {.used.} =
-        # If the proc has implicit return then this will get called
-        `resultIdent` = x
-      template nimAsyncDispatchSetResult(x: untyped) {.used.} =
-        # If the proc doesn't have implicit return then this will get called
-        x
-    procBody.add newCall(ident"nimAsyncDispatchSetResult", blockStmt)
+      # Check whether there is an implicit return
+      when typeof(`blockStmt`) is void:
+        `blockStmt`
+      else:
+        `resultIdent` = `blockStmt`
     procBody.add(createFutureVarCompletions(futureVarIdents, nil))
     procBody.insert(0): quote do:
       {.push warning[resultshadowed]: off.}