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

Comments

Projects
None yet
3 participants
@sid-code
Copy link

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

This comment has been minimized.

Copy link
Member

Araq commented Mar 17, 2015

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

@Araq Araq added the Documentation label Mar 17, 2015

@Araq Araq added Error messages and removed Documentation labels Oct 15, 2018

@Araq Araq closed this in #9387 Oct 16, 2018

Araq added a commit that referenced this issue Oct 16, 2018

improve error message, closes #2361 (#9387)
* improve error message

* use single % operation

narimiran added a commit to narimiran/Nim that referenced this issue Oct 31, 2018

improve error message, closes nim-lang#2361 (nim-lang#9387)
* improve error message

* use single % operation

narimiran added a commit to narimiran/Nim that referenced this issue Nov 1, 2018

improve error message, closes nim-lang#2361 (nim-lang#9387)
* improve error message

* use single % operation

narimiran added a commit that referenced this issue Nov 1, 2018

improve error message, closes #2361 (#9387)
* improve error message

* use single % operation

narimiran added a commit that referenced this issue Nov 1, 2018

improve error message, closes #2361 (#9387)
* 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