summary refs log tree commit diff stats
path: root/tests/arc/tcomputedgotocopy.nim
blob: 07487684a6439e32ae2faed2f32139e1923d1aa4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
discard """
  cmd: '''nim c --mm:arc $file'''
  output: '''
2
2
destroyed
'''
"""

type
  ObjWithDestructor = object
    a: int
proc `=destroy`(self: ObjWithDestructor) =
  echo "destroyed"

proc `=copy`(self: var ObjWithDestructor, other: ObjWithDestructor) =
  echo "copied"

proc test(a: range[0..1], arg: ObjWithDestructor) =
  var iteration = 0
  while true:
    {.computedGoto.}

    let
      b = int(a) * 2
      c = a
      d = arg
      e = arg

    discard c
    discard d
    discard e

    inc iteration

    case a
    of 0:
      assert false
    of 1:
      echo b
      if iteration == 2:
        break

test(1, ObjWithDestructor())