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

compiler error if combine closure iterator, normal iterator and template #15896

Open
a-mr opened this issue Nov 9, 2020 · 1 comment
Open

Comments

@a-mr
Copy link
Contributor

a-mr commented Nov 9, 2020

Compiler reports internal error. (Found when working on #15612).

Example

template declare(body: untyped) =
  if true:
    body
  else:
    body

iterator search(): int {.closure.} =
  yield 11

iterator walk(): int =
  declare():
    yield 0

template process(iter: untyped) =
  for x in iter:
    echo x

for _ in walk():
  process(search())

Current Output

Error: internal error: expr: var not init search_385876041

Expected Output

to compile

Possible Solution

Additional Information

nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2020-11-09
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 53eca459f1d96c710238be95bd3fb048b336f2f3
active boot switches: -d:release

Interestingly, this code works with small modifications such as:

  • if make search normal iterator
  • if make walk closure iterator
  • if change if ... body else: body to just body in declare
@a-mr
Copy link
Contributor Author

a-mr commented Nov 9, 2020

Another weird interaction between templates and closure iterators:

iterator walk(): (int, int) {.closure.} =
  yield (0,1)

for (x0,_) in walk():
  echo x0
Error: internal error: expr(nkVarTuple); unknown node kind

With just a scalar output type (or with a normal iterator) it works.

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

2 participants