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

Recursively calling a closure iterator results in a compiler crash #555

Closed
dom96 opened this issue Jul 30, 2013 · 2 comments
Closed

Recursively calling a closure iterator results in a compiler crash #555

dom96 opened this issue Jul 30, 2013 · 2 comments

Comments

@dom96
Copy link
Contributor

dom96 commented Jul 30, 2013

iterator test(x: int): int {.closure.} =
  var b = test
  if x == 5: yield 1
  else:
    yield b(x+1)

var t = test
echo t()

Crashes with:

Traceback (most recent call last)
nimrod.nim(79)           nimrod
nimrod.nim(55)           HandleCmdLine
main.nim(296)            MainCommand
main.nim(72)             CommandCompileToC
modules.nim(193)         CompileProject
modules.nim(151)         compileModule
passes.nim(192)          processModule
passes.nim(136)          processTopLevelStmt
sem.nim(300)             myProcess
sem.nim(274)             SemStmtAndGenerateGenerics
semstmts.nim(1238)       semStmt
semexprs.nim(778)        semExprNoType
semexprs.nim(1939)       semExpr
semstmts.nim(1055)       semIterator
semstmts.nim(1026)       semProcAux
transf.nim(710)          transformBody
transf.nim(694)          processTransf
transf.nim(682)          transform
transf.nim(108)          transformSons
transf.nim(668)          transform
transf.nim(108)          transformSons
transf.nim(677)          transform
transf.nim(108)          transformSons
transf.nim(594)          transform
transf.nim(135)          transformSym
transf.nim(117)          transformSymAux
lambdalifting.nim(715)   liftIterSym
lambdalifting.nim(218)   getHiddenParam
system.nim(2501)         hiddenRaiseAssert
system.nim(1804)         raiseAssert
Error: unhandled exception: hidden.Kind == nkSym  [EAssertionFailed]
@dom96
Copy link
Contributor Author

dom96 commented Aug 7, 2013

The fact that this does not work seems to be expected. The manual states: "Both inline and closure iterators cannot be recursive."

This may be a showstopper for me.

@Varriount
Copy link
Contributor

This no longer crashes. Instead, the compiler prints out a nice error message reporting the recursion.
Since this is expected behavior, I'm closing the issue.

Clyybber pushed a commit to Clyybber/Nim that referenced this issue Sep 16, 2023
555: document how `--gc:arc` and `--gc:orc` work r=zerbina a=zerbina

## Summary

Only a very short overview of both was previously provided, with the
details only available by inspecting the implementation in the compiler
and its runtime.

In order to make discussion surrounding both easier and more accessible,
a detailed description of how both ARC and ORC work is now provided in
`gc.rst`.



Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com>
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

2 participants