diff options
Diffstat (limited to 'tests/arc/tcomputedgotocopy.nim')
-rw-r--r-- | tests/arc/tcomputedgotocopy.nim | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/arc/tcomputedgotocopy.nim b/tests/arc/tcomputedgotocopy.nim new file mode 100644 index 000000000..07487684a --- /dev/null +++ b/tests/arc/tcomputedgotocopy.nim @@ -0,0 +1,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()) |