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

The async pragma doesn't work properly with a nested proc inside a generic function #10818

Closed
zah opened this issue Mar 10, 2019 · 2 comments
Closed
Labels
Async Everything related to Nim's async Generics Symbol Resolution

Comments

@zah
Copy link
Member

zah commented Mar 10, 2019

The following example fails to compile with the the error

example.nim(9, 11) Error: undeclared identifier: 'await'

Example

import
  asyncdispatch

type
  AsyncProc = proc(): Future[void]

proc makeCallback[T](v: T): AsyncProc =
  result = proc() {.async.} =
    await sleepAsync(100)
  
let c = makeCallback(10)

The problem manifests only when the makeCallback proc is generic. At the moment, it's possible to work-around the issue by manually simulating the low-level mechanics of await:

proc makeCallback[T](v: T): AsyncProc =
  result = proc() {.async.} =
    var future = sleepAsync(100)
    yield future
    if future.failed: ...

Additional Information

$ nim -v
Nim Compiler Version 0.19.9 [Linux: amd64]
git hash: b9f8528db675927aacc6443ae3a363711bb41945
active boot switches: -d:release
@zah zah added Generics Async Everything related to Nim's async labels Mar 10, 2019
@zah zah changed the title The async pragma cannot be used on a nested proc inside a generic function The async pragma doesn't work properly with a nested proc inside a generic function Mar 10, 2019
@mratsim
Copy link
Collaborator

mratsim commented Mar 15, 2019

Sounds like another case of #8677 - generics early symbol resolution issue

@ringabout
Copy link
Member

ringabout commented Nov 7, 2020

same issue as #15804
And fixed by #15820

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 Generics Symbol Resolution
Projects
None yet
Development

No branches or pull requests

3 participants