-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implicit return working for async proc #20933
Conversation
Docs CI failing because of #20938 |
Please rebase. |
let resultIdent = ident"result" | ||
procBody.add quote do: | ||
template setResult(x: `subRetType`) {.used.} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
* 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 <[email protected]>
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 <[email protected]>
Closes #11558
Uses an overloaded template to tell if the block has an implicit return or not