import macros macro addEcho(s: untyped): stmt = s.body.add(newCall("echo", newStrLitNode("OK"))) result = s proc f1() {.addEcho.} = let i = 1+2 echo i
You have to use untyped because with stmt, Nim seems to create a symbol f1 beforehand and then gets confused about it because you return a proc f1 again with the same signature. This should probably be reported as bug, because it should at least generate a sensible error message.