Open nblaxall opened 2 years ago
Scope leakage fixed in https://github.com/nim-lang/Nim/pull/19288
About this:
let d = collect:
let p = 2
if p == 2:
for i in 1..9: i
else:
for i in 1..9: i * p # breaks
I'm not really sure if this is supposed to work as-is. You can make it work by changing the code so that if
is inside the loop:
let d = collect:
let p = 2
for i in 1..9:
if p == 2:
i
else:
i * p
This was tested on https://play.nim-lang.org/#ix=3Jnf and also on my laptop (Nim Compiler Version 1.6.2 [MacOSX: amd64])
Sugar's
collect
seems to leak scope, plus maybe another bug to do with if/else's in collect:Example
here is the output of https://play.nim-lang.org/#ix=3Jnf:
Hint: used config file '/playground/nim/config/nim.cfg' [Conf] Hint: used config file '/playground/nim/config/config.nims' [Conf] ............................................................. /usercode/in.nim(25, 9) template/generic instantiation of
collect
from here /usercode/in.nim(30, 22) Error: expression 'i * p' is of type 'int' and has to be used (or discarded)