tuse_result_prevents_sinks.nim 583 B

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