tshallowcopy_closures.nim 509 B

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