diff options
author | Araq <rumpf_a@web.de> | 2013-04-08 00:10:34 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-04-08 00:10:34 +0200 |
commit | bb3f648bd2d9b01da86ae73b491eabaaa72b7cca (patch) | |
tree | 589a9e1be86fcb9a0c7ec8ac73c2dfa189775350 /tests/run/tdestructor.nim | |
parent | d57fe6c904e996dca5adc0efa4d26c85032c1dc5 (diff) | |
download | Nim-bb3f648bd2d9b01da86ae73b491eabaaa72b7cca.tar.gz |
improvements for destructors
Diffstat (limited to 'tests/run/tdestructor.nim')
-rw-r--r-- | tests/run/tdestructor.nim | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/run/tdestructor.nim b/tests/run/tdestructor.nim new file mode 100644 index 000000000..8aae2fce2 --- /dev/null +++ b/tests/run/tdestructor.nim @@ -0,0 +1,26 @@ +discard """ + output: '''some text +Destructor called!''' +""" + +type + TMyObj = object + x, y: int + p: pointer + +proc destruct(o: var TMyObj) {.destructor.} = + if o.p != nil: dealloc o.p + echo "Destructor called!" + +proc open: TMyObj = + # allow for superfluous () + result = (TMyObj(x: 1, y: 2, p: alloc(3))) + + +proc `$`(x: TMyObj): string = $x.y + +proc main() = + var x = open() + echo "some text" + +main() |