tshallowcopy_closures.nim 472 B

1234567891011121314151617181920212223242526272829303132
  1. discard """
  2. ccodecheck: "!@('{' \\s* 'NI HEX3Astate;' \\s* '}')"
  3. """
  4. # bug #1803
  5. type TaskFn = iterator (): float
  6. iterator a1(): float {.closure.} =
  7. var k = 10
  8. while k > 0:
  9. echo "a1 ", k
  10. dec k
  11. yield 1.0
  12. iterator a2(): float {.closure.} =
  13. var k = 15
  14. while k > 0:
  15. echo "a2 ", k
  16. dec k
  17. yield 2.0
  18. var
  19. x = a1
  20. y = a2
  21. z: TaskFn
  22. discard x()
  23. z = x #shallowCopy(z, x)
  24. z = y #shallowCopy(z, y)
  25. discard x()