-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Using a variable inside of an iterator does not work.
Example
type
Game* = ref object
proc free*(game: Game) =
var mixNumOpened:cint = 0
for i in 0..<mixNumOpened:
mixNumOpened -= 1
proc newGame*(): Game =
new result, free
var
game*: GameCurrent Output
It results in this error.
/opt/homebrew/Cellar/nim/1.6.0/nim/lib/system/iterators_1.nim(129, 17) Error: internal error: expr: var not init mixNumOpened_452984858
Expected Output
It's expected to compile successfully or with an error that's not internal
Possible Solution
Changing the object around to use =destroy seems to fix the issue
type
GameObj = object
fTest: cint
Game* = ref GameObj
proc `=destroy`(obj: var GameObj) =
echo "destroy"
var mixNumOpened:cint = 0
for i in 0..<mixNumOpened:
mixNumOpened -= 1
var
game*: Game
echo "hello"
game = new Game
game.fTest = 3
echo game.fTestAdditional Information
This was an attempt at compiling nimgame2 using 1.6.0
Tested mostly on Nim Compiler Version 1.6.0 [MacOSX: arm64], but issue also appears on the latest devel branch at 99f8793