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

Illegal capture on async proc (except when the argument is seq) #2361

Closed
sid-code opened this issue Mar 17, 2015 · 1 comment · Fixed by #9387
Closed

Illegal capture on async proc (except when the argument is seq) #2361

sid-code opened this issue Mar 17, 2015 · 1 comment · Fixed by #9387
Assignees

Comments

@sid-code
Copy link

@sid-code sid-code commented Mar 17, 2015

If I try to compile the following (I'm aware that the code doesn't do what it intends to):

proc sleepsort(xs: seq[int]) {.async.} =
  for x in xs:
    await sleepAsync(x)
    echo x

The compiler tells me this:

Error: illegal capture 'xs'

Now, if I change varargs to seq, it works fine. Is there a reason for this?

I've noticed that this happens for many data types, not just varargs. I just find it strange that it should work for seq.

@Araq
Copy link
Member

@Araq Araq commented Mar 17, 2015

You cannot capture openArray/varargs or 'var T' as that would violate memory safety.

@Araq Araq closed this in #9387 Oct 16, 2018
Araq added a commit that referenced this issue Oct 16, 2018
* improve error message

* use single % operation
narimiran added a commit to narimiran/Nim that referenced this issue Oct 31, 2018
* improve error message

* use single % operation
narimiran added a commit to narimiran/Nim that referenced this issue Nov 1, 2018
* improve error message

* use single % operation
narimiran added a commit that referenced this issue Nov 1, 2018
* improve error message

* use single % operation
narimiran added a commit that referenced this issue Nov 1, 2018
* improve error message

* use single % operation

(cherry picked from commit e8cf289)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants