Skip to content
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

Async causes return, which is only run if nothing raises, to be considered as as always run. #12530

Open
kayabaNerve opened this issue Oct 26, 2019 · 1 comment
Labels
Async Everything related to Nim's async

Comments

@kayabaNerve
Copy link
Collaborator

If a raisable statement and a return is inside a try/catch, any code after the raises will be considered unreachable, despite the fact that if the raisable statement raises the return is not executed.

Example

import asyncdispatch

proc trySync() {.async.} =
  raise newException(ValueError, "")

proc x() {.async.} =
  try:
    await trySync()
    return
  except ValueError:
    discard
  
  echo "Hello"

Current Output

/usercode/in.nim(3, 18) template/generic instantiation of `async` from here
/usercode/in.nim(4, 3) Error: unreachable statement after 'return' statement or '{.noReturn.}' proc

Expected Output

Hello

Additional Information

Tested on Nim Playground 1.0.2.

@disruptek
Copy link
Contributor

Whenever you have a situation like this, it's worked-around by providing a trailing block that the async can gobble up:

proc foo() {.async.} =
  block:
    raise newException(Exception, "")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Async Everything related to Nim's async
Projects
None yet
Development

No branches or pull requests

3 participants