tuse_result_prevents_sinks.nim 447 B

1234567891011121314151617181920212223242526272829303132
  1. discard """
  2. output: ""
  3. """
  4. # bug #9594
  5. type
  6. Foo = object
  7. i: int
  8. proc `=`(self: var Foo; other: Foo) =
  9. self.i = other.i + 1
  10. proc `=sink`(self: var Foo; other: Foo) =
  11. self.i = other.i
  12. proc `=destroy`(self: var Foo) = discard
  13. proc test(): Foo =
  14. result = Foo()
  15. let temp = result
  16. doAssert temp.i > 0
  17. return result
  18. proc testB(): Foo =
  19. result = Foo()
  20. let temp = result
  21. doAssert temp.i > 0
  22. discard test()
  23. discard testB()