The following file fails when testing with 0.10.3 sync'd as of approximately 0700 UTC. Can someone clue me in on why it would fail with aProc redefinition? As a side note, it works if the template is immediate.
template t1(name: string, body: stmt): stmt =
echo "t1: name=", name
body
t1 "t1_1":
proc aProc(s: string) =
echo "aProc: s=", s
aProc("yo")
aProc("dude")
With redefinition of 'aProc'
$ nim c -r --verbosity:2 --hints:off --warnings:off t1
t1.nim(5, 3) Info: template/generic instantiation from here
t1.nim(6, 2) Error: redefinition of 'aProc'
proc aProc(s: string) =
^
But if the same template is immediate:
template t1(name: string, body: stmt): stmt {.immediate.} =
echo "t1: name=", name
body
t1 "t1_1":
proc aProc(s: string) =
echo "aProc: s=", s
aProc("yo")
aProc("dude")
Works as I would expect
$ nim c -r --verbosity:0 --hints:off --warnings:off t1
t1: name=t1_1
aProc: s=yo
aProc: s=dude
Well to pass an argument to stmt it is "resolved", so type checking and symbol table manipulations are performed. So 'aProc' is added to the symbol table for the t1 invocation. Then you 'return' that block and it's resolved again and so again 'aProc' is added to the symbol table. You can use expr instead of stmt here and then it should work. immediate circumvents the overloading resolution mechanism and so doesn't have this problem.
And yes, it's weird but I'm not sure yet how to change the spec for stmt.