For some reason, putting a closure in the setup section of a test suite causes any test that does not use it to blow up the compiler.
Here's the problem isolated:
import unittest
suite "suite":
setup:
var x = 4
proc closed: int = x
test "the test":
check closed() == 4
test "another test":
check true
When the C compiler tries to compile the generated code, it complains about x being not defined in a function called closed_####. The entire message is here:
$ nim c -r --parallelBuild:1 --verbosity:0 test.nim
<SNIP>
/home/bozaloshtsh/code/nim/nimcache/test.c: In function ‘closed_138243’:
/home/bozaloshtsh/code/nim/nimcache/test.c:656:11: error: ‘x’ undeclared (first use in this function)
result = x;
^
/home/bozaloshtsh/code/nim/nimcache/test.c:656:11: note: each undeclared identifier is reported only once for each function it appears in
Error: execution of an external program failed
Even more strangely, removing the second unit test makes the code compile and the first test case passes. The problem seems to stem from the fact that the closure is initialized but not being used in the second test case, and this is messing with the compiler, but how?