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

String or sequences inside a loop are not cleared in each iteration #11510

Closed
b3liever opened this issue Jun 16, 2019 · 1 comment

Comments

@b3liever
Copy link
Contributor

commented Jun 16, 2019

A string needs to be explicitly initialized inside a loop so its contents are cleared in each iteration. There is a difference in the following program's output between nim "current" and newruntime. The bug is about newruntime.

Example

proc main =
  for i in 0 ..< 4:
    var buffer: seq[int] # = @[] # uncomment to make it work 
    # var buffer: string # also this is broken
    buffer.add i
    echo buffer
main()

Current Output

When compiling with --newruntime

@[0]
@[0, 1]
@[0, 1, 2]
@[0, 1, 2, 3]

Expected Output

@[0]
@[1]
@[2]
@[3]

Additional Information

$ nim -v
Nim Compiler Version 0.20.99 [Linux: amd64]
Compiled at 2019-06-08
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: bce908f6ee9f24346641310d8f7f8971e92ffe01
active boot switches: -d:release
@Wh1teDuke

This comment has been minimized.

Copy link
Contributor

commented Jun 16, 2019

Related #10938

@Araq Araq closed this in c0db170 Jul 3, 2019

narimiran added a commit that referenced this issue Jul 8, 2019

fixes #11510
(cherry picked from commit c0db170)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.