tmore_regressions.nim 686 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. discard """
  2. output: '''0
  3. 0.0'''
  4. """
  5. # bug #11494
  6. import macros
  7. macro staticForEach(arr: untyped, body: untyped): untyped =
  8. result = newNimNode(nnkStmtList)
  9. arr.expectKind(nnkBracket)
  10. for n in arr:
  11. let b = copyNimTree(body)
  12. result.add quote do:
  13. block:
  14. type it {.inject.} = `n`
  15. `b`
  16. template forEveryMatchingEntity*() =
  17. staticForEach([int, string, float]):
  18. var a: it
  19. echo a
  20. forEveryMatchingEntity()
  21. # bug #11483
  22. proc main =
  23. template first(body) =
  24. template second: var int =
  25. var o: int
  26. var i = addr(o)
  27. i[]
  28. body
  29. first:
  30. second = 5
  31. second = 6
  32. main()