summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2017-11-29 00:01:27 +0100
committerAraq <rumpf_a@web.de>2017-11-29 00:01:27 +0100
commitc43f718301bb1dbd8d2594159de7b6bb4debc1bf (patch)
tree270ff90255cbcc016f1b7fc5f264761c0c8bb64c /tests
parent7660e59afe88916b8d0403295dd9dd242fc429d0 (diff)
downloadNim-c43f718301bb1dbd8d2594159de7b6bb4debc1bf.tar.gz
destructors: some improvements for bug #4214: object constructors are moved too
Diffstat (limited to 'tests')
-rw-r--r--tests/destructor/tmove_objconstr.nim32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/destructor/tmove_objconstr.nim b/tests/destructor/tmove_objconstr.nim
new file mode 100644
index 000000000..3e8a64435
--- /dev/null
+++ b/tests/destructor/tmove_objconstr.nim
@@ -0,0 +1,32 @@
+
+discard """
+output:  '''test created
+test destroyed 0'''
+  cmd: '''nim c --newruntime $file'''
+"""
+
+# bug #4214
+type
+  Data = object
+    data: string
+    rc: int
+
+proc `=destroy`(d: var Data) =
+  dec d.rc
+  echo d.data, " destroyed ", d.rc
+
+proc `=`(dst: var Data, src: Data) =
+  echo src.data, " copied"
+  dst.data = src.data & " (copy)"
+  dec dst.rc
+  inc dst.rc
+
+proc initData(s: string): Data =
+  result = Data(data: s, rc: 1)
+  echo s, " created"
+
+proc main =
+  var x = initData"test"
+
+when isMainModule:
+  main()