summary refs log tree commit diff stats
path: root/tests/arc
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2021-07-20 22:15:06 +0200
committerGitHub <noreply@github.com>2021-07-20 22:15:06 +0200
commitf8519657c43f458db9c915cec62c59022041eb05 (patch)
treebaad0a54d733312a55e495d877c3847f928a02e4 /tests/arc
parentcf0cf32d276002e850a87667fff62c4df12999d6 (diff)
downloadNim-f8519657c43f458db9c915cec62c59022041eb05.tar.gz
fixes #18469 (#18544)
* fixes #18469

* Update compiler/injectdestructors.nim
Diffstat (limited to 'tests/arc')
-rw-r--r--tests/arc/tcursor_field_obj_constr.nim44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/arc/tcursor_field_obj_constr.nim b/tests/arc/tcursor_field_obj_constr.nim
new file mode 100644
index 000000000..b87f734bd
--- /dev/null
+++ b/tests/arc/tcursor_field_obj_constr.nim
@@ -0,0 +1,44 @@
+discard """
+  output: '''a
+b
+c'''
+  cmd: "nim c --gc:arc $file"
+"""
+
+# bug #18469
+
+type
+  Edge = object
+    neighbor {.cursor.}: Node
+
+  NodeObj = object
+    neighbors: seq[Edge]
+    label: string
+    visited: bool
+  Node = ref NodeObj
+
+  Graph = object
+    nodes: seq[Node]
+
+proc `=destroy`(x: var NodeObj) =
+  echo x.label
+  `=destroy`(x.neighbors)
+  `=destroy`(x.label)
+
+proc addNode(self: var Graph; label: string): Node =
+  self.nodes.add(Node(label: label))
+  result = self.nodes[^1]
+
+proc addEdge(self: Graph; source, neighbor: Node) =
+  source.neighbors.add(Edge(neighbor: neighbor))
+
+proc main =
+  var graph: Graph
+  let nodeA = graph.addNode("a")
+  let nodeB = graph.addNode("b")
+  let nodeC = graph.addNode("c")
+
+  graph.addEdge(nodeA, neighbor = nodeB)
+  graph.addEdge(nodeA, neighbor = nodeC)
+
+main()