summary refs log tree commit diff stats
path: root/tests/destructor/tmove_objconstr.nim
diff options
context:
space:
mode:
authorDaniil Yarancev <21169548+Yardanico@users.noreply.github.com>2018-01-07 21:02:00 +0300
committerGitHub <noreply@github.com>2018-01-07 21:02:00 +0300
commitfb44c522e6173528efa8035ecc459c84887d0167 (patch)
treea2f5e98606be265981a5f72748896967033e23d7 /tests/destructor/tmove_objconstr.nim
parentccf99fa5ce4fe992fb80dc89271faa51456c3fa5 (diff)
parente23ea64c41e101d4e1d933f0b015f51cc6c2f7de (diff)
downloadNim-fb44c522e6173528efa8035ecc459c84887d0167.tar.gz
Merge pull request #1 from nim-lang/devel
upstream
Diffstat (limited to 'tests/destructor/tmove_objconstr.nim')
-rw-r--r--tests/destructor/tmove_objconstr.nim59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/destructor/tmove_objconstr.nim b/tests/destructor/tmove_objconstr.nim
new file mode 100644
index 000000000..8aa12ed05
--- /dev/null
+++ b/tests/destructor/tmove_objconstr.nim
@@ -0,0 +1,59 @@
+
+discard """
+output:  '''test created
+test destroyed 0
+1
+2
+3
+4
+Pony is dying!'''
+  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 pointlessWrapper(s: string): Data =
+  result = initData(s)
+
+proc main =
+  var x = pointlessWrapper"test"
+
+when isMainModule:
+  main()
+
+# bug #985
+
+type
+    Pony = object
+        name: string
+
+proc `=destroy`(o: var Pony) =
+  echo "Pony is dying!"
+
+proc getPony: Pony =
+    result.name = "Sparkles"
+
+iterator items(p: Pony): int =
+    for i in 1..4:
+        yield i
+
+for x in getPony():
+    echo x