summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/destroyer.nim4
-rw-r--r--compiler/docgen.nim27
-rw-r--r--tests/destructor/tmove_objconstr.nim59
3 files changed, 82 insertions, 8 deletions
diff --git a/compiler/destroyer.nim b/compiler/destroyer.nim
index 36839bf0b..729480f81 100644
--- a/compiler/destroyer.nim
+++ b/compiler/destroyer.nim
@@ -210,7 +210,7 @@ template recurse(n, dest) =
     dest.add p(n[i], c)
 
 proc moveOrCopy(dest, ri: PNode; c: var Con): PNode =
-  if ri.kind in nkCallKinds:
+  if ri.kind in nkCallKinds+{nkObjConstr}:
     result = genSink(ri.typ, dest)
     # watch out and no not transform 'ri' twice if it's a call:
     let ri2 = copyNode(ri)
@@ -312,7 +312,7 @@ proc injectDestructorCalls*(owner: PSym; n: PNode): PNode =
     result.add body
 
   when defined(nimDebugDestroys):
-    if owner.name.s == "createSeq":
+    if owner.name.s == "main" or true:
       echo "------------------------------------"
       echo owner.name.s, " transformed to: "
       echo result
diff --git a/compiler/docgen.nim b/compiler/docgen.nim
index 0861c25b2..65dcb73c9 100644
--- a/compiler/docgen.nim
+++ b/compiler/docgen.nim
@@ -553,12 +553,24 @@ proc genJsonItem(d: PDoc, n, nameNode: PNode, k: TSymKind): JsonNode =
 proc checkForFalse(n: PNode): bool =
   result = n.kind == nkIdent and cmpIgnoreStyle(n.ident.s, "false") == 0
 
-proc traceDeps(d: PDoc, n: PNode) =
+proc traceDeps(d: PDoc, it: PNode) =
   const k = skModule
-  if d.section[k] != nil: add(d.section[k], ", ")
-  dispA(d.section[k],
-        "<a class=\"reference external\" href=\"$1.html\">$1</a>",
-        "$1", [rope(getModuleName(n))])
+
+  if it.kind == nkInfix and it.len == 3 and it[2].kind == nkBracket:
+    let sep = it[0]
+    let dir = it[1]
+    let a = newNodeI(nkInfix, it.info)
+    a.add sep
+    a.add dir
+    a.add sep # dummy entry, replaced in the loop
+    for x in it[2]:
+      a.sons[2] = x
+      traceDeps(d, a)
+  else:
+    if d.section[k] != nil: add(d.section[k], ", ")
+    dispA(d.section[k],
+          "<a class=\"reference external\" href=\"$1.html\">$1</a>",
+          "$1", [rope(getModuleName(it))])
 
 proc generateDoc*(d: PDoc, n: PNode) =
   case n.kind
@@ -793,7 +805,10 @@ proc commandRstAux(filename, outExt: string) =
     var outp: string
     if filename.len == 0:
       inc(d.id)
-      outp = completeGeneratedFilePath(splitFile(d.filename).name & "_snippet_" & $d.id & ".nim")
+      let nameOnly = splitFile(d.filename).name
+      let subdir = getNimcacheDir() / nameOnly
+      createDir(subdir)
+      outp = subdir / (nameOnly & "_snippet_" & $d.id & ".nim")
     elif isAbsolute(filename):
       outp = filename
     else:
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