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

Can't call closure iterator from inside an async function #16416

Open
kayabaNerve opened this issue Dec 20, 2020 · 1 comment
Open

Can't call closure iterator from inside an async function #16416

kayabaNerve opened this issue Dec 20, 2020 · 1 comment

Comments

@kayabaNerve
Copy link
Collaborator

Function echo outputs the wrong string.

Example

iterator x(): int {.closure.} =
  discard

proc y() {.async.} =
  for z in x():
    discard
    
waitFor y()

Current Output

/usercode/in.nim(7, 7) Error: internal error: expr: var not init x_17965377
No stack traceback available
To create a stacktrace, rerun compilation with './koch temp c <file>', see https://nim-lang.github.io/Nim/intern.html#debugging-the-compiler for details

Expected Output

Additional Information

Present since at least Nim 1.2.4, is present in latest (1.4.2). Instead of calling x, using var foo = x and then calling foo causes a codegen error.

Hint: used config file '/playground/nim/config/nim.cfg' [Conf]
Hint: used config file '/playground/nim/config/config.nims' [Conf]
..................................
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_assertions.nim.c.o /usercode/nimcache/stdlib_assertions.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_dollars.nim.c.o /usercode/nimcache/stdlib_dollars.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_system.nim.c.o /usercode/nimcache/stdlib_system.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_math.nim.c.o /usercode/nimcache/stdlib_math.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_strutils.nim.c.o /usercode/nimcache/stdlib_strutils.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_options.nim.c.o /usercode/nimcache/stdlib_options.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_times.nim.c.o /usercode/nimcache/stdlib_times.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_os.nim.c.o /usercode/nimcache/stdlib_os.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_heapqueue.nim.c.o /usercode/nimcache/stdlib_heapqueue.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_deques.nim.c.o /usercode/nimcache/stdlib_deques.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_cstrutils.nim.c.o /usercode/nimcache/stdlib_cstrutils.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_asyncfutures.nim.c.o /usercode/nimcache/stdlib_asyncfutures.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_monotimes.nim.c.o /usercode/nimcache/stdlib_monotimes.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_nativesockets.nim.c.o /usercode/nimcache/stdlib_nativesockets.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_selectors.nim.c.o /usercode/nimcache/stdlib_selectors.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/stdlib_asyncdispatch.nim.c.o /usercode/nimcache/stdlib_asyncdispatch.nim.c [Exec]
Hint: gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/@min.nim.c.o /usercode/nimcache/@min.nim.c [Exec]
/usercode/nimcache/@min.nim.c: In function 'yIter__aqJRG7LPaI9c3tRfsLoZqKA':
/usercode/nimcache/@min.nim.c:562:77: error: request for member 'ClE_0' in something not a structure or union
     asgnRef((void**) (&(*colonenvP_).foo1.ClE_0), x__ekSWG86elE9byusFc3hPHFw.ClE_0);
                                                                             ^
/usercode/nimcache/@min.nim.c:563:58: error: request for member 'ClP_0' in something not a structure or union
     (*colonenvP_).foo1.ClP_0 = x__ekSWG86elE9byusFc3hPHFw.ClP_0;
                                                          ^
Error: execution of an external program failed: 'gcc -c  -w -fmax-errors=3   -I/playground/nim/lib -I/usercode -o /usercode/nimcache/@min.nim.c.o /usercode/nimcache/@min.nim.c'
@metagn
Copy link
Collaborator

metagn commented Feb 15, 2021

This gives the same var not init error:

iterator x(): int {.closure.} =
  discard

proc y() =
  iterator z(): int {.closure.} =
    for a in x():
      yield a
  
  let foo = z
    
y()
/usercode/in.nim(6, 9) Error: internal error: expr: var not init x_4602093

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants