tmisc_destructors.nim 689 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. discard """
  2. output: '''@[0]
  3. @[1]
  4. @[2]
  5. @[3]'''
  6. joinable: false
  7. """
  8. # bug #6434
  9. type
  10. Foo* = object
  11. boo: int
  12. var sink_counter = 0
  13. var assign_counter = 0
  14. proc `=sink`(dest: var Foo, src: Foo) =
  15. sink_counter.inc
  16. proc `=`(dest: var Foo, src: Foo) =
  17. assign_counter.inc
  18. proc test(): auto =
  19. var a,b : Foo
  20. return (a, b, Foo(boo: 5))
  21. var (a, b, _) = test()
  22. doAssert assign_counter == 0
  23. doAssert sink_counter == 12 # + 3 because of the conservative tuple unpacking transformation
  24. # bug #11510
  25. proc main =
  26. for i in 0 ..< 4:
  27. var buffer: seq[int] # = @[] # uncomment to make it work
  28. # var buffer: string # also this is broken
  29. buffer.add i
  30. echo buffer
  31. main()