Implicit return working for async proc#20933
Conversation
|
Docs CI failing because of #20938 |
|
Please rebase. |
| procBody = newStmtList() | ||
| let resultIdent = ident"result" | ||
| procBody.add quote do: | ||
| template setResult(x: `subRetType`) {.used.} = |
There was a problem hiding this comment.
We've considered a similar thing in chronos so that nim-result can work better - status-im/nim-chronos#297 - perhaps we should coordinate the mechanism here - one thing that often comes up is symbol resolution issues - ie template lookup scope is confusing / broken and has a tendency to ruin unrelated code when used together with generics: status-im/nim-stew#161 - as a consequence, we've started using more "unique" names, also for "private" templates like this.
There was a problem hiding this comment.
From reading those PR's I think this is a different problem to whats in them. This doesn't effect how its returned but just means that code like this can now compile and work (Doesn't effect how normal return and result = works)
# Not exactly a good async example, but just needed something basic
proc foo(x: int): Future[string] {.async.} =
if x mod 2 == 0:
"even"
else:
"odd"But see what you mean about needing unique names. Maybe could make it very explicit like asyncDispatchSetResult?
|
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
|
@Araq this needed a more unique name for the template |
|
Sorry my fault, I forgot to rename template. |
Based on nim-lang/Nim#20933 * simplify body generation code to use `quote do` * clean up some variables and assignments
* Implicit return working for asyncdispatch proc Closes nim-lang#11558 * Test case * Test that return value is actually used * Update tests/async/t11558.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Implicit return working for asyncdispatch proc Closes nim-lang#11558 * Test case * Test that return value is actually used * Update tests/async/t11558.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Based on nim-lang/Nim#20933 * simplify body generation code to use `quote do` * clean up some variables and assignments
Based on nim-lang/Nim#20933 * simplify body generation code to use `quote do` * clean up some variables and assignments
* Implicit return working for asyncdispatch proc Closes nim-lang#11558 * Test case * Test that return value is actually used * Update tests/async/t11558.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Closes #11558
Uses an overloaded template to tell if the block has an implicit return or not