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 when returning new iterator #24662

Open
sonicsmooth opened this issue Feb 1, 2025 · 0 comments
Open

Compiler error when returning new iterator #24662

sonicsmooth opened this issue Feb 1, 2025 · 0 comments

Comments

@sonicsmooth
Copy link

sonicsmooth commented Feb 1, 2025

Description

Sounds like this is related to #17632 .

Creating an iterator-that-calls-an-iterator yields compiler error Error: internal error: expr: var not init counter_520093758

iterator counter(frm, to: int): int {.closure.} =
  var x = frm
  while x < to:
    yield x
    x += 1


proc makeCounter(frm: int): iterator(to2: int): int {.closure.} =
  iterator(to2: int): int {.closure.} = 
    for x in counter(frm,to2):
      yield x

var ctr = makeCounter(2)
echo ctr(5)

Nim Version

Nim Compiler Version 2.2.0 [Windows: amd64]
Compiled at 2024-10-02

Current Output

c:\Users\Mikey\source\blocks\nim\tst.nim(11, 9) Error: internal error: expr: var not init counter_520093759
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

No compiler internal error.

Known Workarounds

I'm unable to apply any of the workarounds I've seen for this issue.
However changing proc to template seems to fix the problem:

Additional Information

No response

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

No branches or pull requests

1 participant