tprevent_assign2.nim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. discard """
  2. errormsg: "'=dup' is not available for type <Foo>, which is inferred from unavailable '=copy'; requires a copy because it's not the last read of 'otherTree'; another read is done here: tprevent_assign2.nim(51, 31); routine: preventThis"
  3. file: "tprevent_assign2.nim"
  4. line: 49
  5. """
  6. type
  7. Foo = object
  8. x: int
  9. proc `=destroy`(f: var Foo) = f.x = 0
  10. proc `=copy`(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()