This code works with default GC but fails with --gc:arc at C compiler stage (probably due to some error in handling of inline iterators?).
Found in https://github.com/cheatfate/nimcrypto
Also affects https://github.com/oprypin/nim-random
Compile nim c --gc:arc a.nim
# a.nim
import b
# b.nim
var vectors = @["a", "b", "c", "d", "e"]
iterator testVectors(): string =
for vector in vectors:
yield vector
for item in testVectors():
echo item
/home/dian/.cache/nim/a_d/@ma.nim.c: In function 'NimMainModule':
/home/dian/.cache/nim/a_d/@ma.nim.c:153:40: error: 'vector' undeclared (first use in this function)
153 | eqdestroy___dS1BF3Vxjg9aJMmmhVJKSpQ((&vector));
| ^~~~~~
/home/dian/.cache/nim/a_d/@ma.nim.c:153:40: note: each undeclared identifier is reported only once for each function it appears in
Error: execution of an external compiler program 'gcc -c -w -I/home/dian/.nim/lib -I/home/dian/Projects/data/nimcrypto -o /home/dian/.cache/nim/a_d/@ma.nim.c.o /home/dian/.cache/nim/a_d/@ma.nim.c' failed with exit code: 1
b
c
d
e
$ nim -v
Nim Compiler Version 1.3.1 [Linux: amd64]
Compiled at 2020-05-04
Copyright (c) 2006-2020 by Andreas Rumpf
git hash: 603010f8c9d9655bb0fa3f91dc0bd1b76d3a0bd3
active boot switches: -d:release
Seems like the C file for a.nim contains this:
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
eqdestroy___dS1BF3Vxjg9aJMmmhVJKSpQ((&vector));
eqdestroy___dS1BF3Vxjg9aJMmmhVJKSpQ((&item__UH5qJR1ymSwpE9czTaF5TUA));
eqdestroy___0RiuPw9cXhtLB9a2rQ2jA69cg((&vectors__VZYSpAXtGThCXa5om8XAYg));
nimTestErrorFlag();
}
but it should be in the C file for b.nim instead.
EDIT:
Or maybe the issue is that the C file for a.nim only contains two of these 3:
/* section: NIM_merge_VARS */
extern NimStringV2 item__UH5qJR1ymSwpE9czTaF5TUA;
extern tySequence__sM4lkSb7zS6F7OVMvW9cffQ vectors__VZYSpAXtGThCXa5om8XAYg;
(there's no definition for vector)
I do have a fix for this issue
Most helpful comment
I do have a fix for this issue