tmacro7.nim 624 B

12345678910111213141516171819202122232425262728293031323334353637
  1. discard """
  2. output: '''
  3. calling!stuff
  4. calling!stuff
  5. '''
  6. disabled: true
  7. """
  8. # this test modifies an already semchecked ast (bad things happen)
  9. # this test relies on the bug #4547
  10. # issue #7792
  11. import macros
  12. proc callProc(str: string) =
  13. echo "calling!" & str
  14. macro testMacro(code: typed): untyped =
  15. let stmtList = newNimNode(nnkStmtList)
  16. let stmts = code[6]
  17. for n in stmts.children:
  18. # the error happens here
  19. stmtList.add(newCall(bindSym("callProc"), newLit("stuff")))
  20. code[6] = stmtList
  21. result = newEmptyNode()
  22. proc main() {.testMacro.} =
  23. echo "test"
  24. echo "test2"
  25. when isMainModule:
  26. main()