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