tmisc_destructors.nim 671 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 createFoo(): Foo = Foo(boo: 0)
  19. proc test(): auto =
  20. var a, b = createFoo()
  21. return (a, b, Foo(boo: 5))
  22. var (ag, bg, _) = test()
  23. doAssert assign_counter == 0
  24. doAssert sink_counter == 0
  25. # bug #11510
  26. proc main =
  27. for i in 0 ..< 4:
  28. var buffer: seq[int] # = @[] # uncomment to make it work
  29. # var buffer: string # also this is broken
  30. buffer.add i
  31. echo buffer
  32. main()