tprevent_assign2.nim 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. discard """
  2. errormsg: "'=copy' is not available for type <Foo>; requires a copy because it's not the last read of 'otherTree'"
  3. file: "tprevent_assign2.nim"
  4. line: 48
  5. """
  6. type
  7. Foo = object
  8. x: int
  9. proc `=destroy`(f: var Foo) = f.x = 0
  10. proc `=`(a: var Foo; b: Foo) {.error.} # = a.x = b.x
  11. proc `=sink`(a: var Foo; b: Foo) = a.x = b.x
  12. proc createTree(x: int): Foo =
  13. Foo(x: x)
  14. proc take2(a, b: sink Foo) =
  15. echo a.x, " ", b.x
  16. when false:
  17. var otherTree: Foo
  18. try:
  19. for i in 0..3:
  20. while true:
  21. #if i == 0:
  22. otherTree = createTree(44)
  23. case i
  24. of 0:
  25. echo otherTree
  26. take2(createTree(34), otherTree)
  27. of 1:
  28. take2(createTree(34), otherTree)
  29. else:
  30. discard
  31. finally:
  32. discard
  33. proc preventThis() =
  34. var otherTree: Foo
  35. for i in 0..3:
  36. while true:
  37. if i == 0:
  38. otherTree = createTree(44)
  39. case i
  40. of 0:
  41. echo otherTree
  42. take2(createTree(34), otherTree)
  43. of 1:
  44. take2(createTree(34), otherTree)
  45. else:
  46. discard
  47. #allowThis()
  48. preventThis()