titeratormacro.nim 325 B

123456789101112131415161718
  1. # issue #16413
  2. import std/macros
  3. macro identity(x: untyped) =
  4. result = x.copy()
  5. result[6] = quote do:
  6. yield 1
  7. discard result.toStrLit
  8. iterator demo(): int {.identity.}
  9. iterator demo2(): int {.identity.} = discard # but this works as expected
  10. var s: seq[int] = @[]
  11. for e in demo():
  12. s.add(e)
  13. doAssert s == @[1]