summary refs log tree commit diff stats
path: root/tests/arc
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2020-07-30 17:32:48 +0200
committerGitHub <noreply@github.com>2020-07-30 17:32:48 +0200
commitd130175342f2b7c1bf87dd05c86509f04cf78154 (patch)
tree7638d98b3fc037bf658a061f17fc636a6198a632 /tests/arc
parent32c6146200196398986bee092b4ef4a0f82d90b2 (diff)
downloadNim-d130175342f2b7c1bf87dd05c86509f04cf78154.tar.gz
cursor and mutation tracking fixes (#15113)
* fixes #15110
* fixes #15096

* prepare varpartitions for cursor inference
* new cursor inference begins to work
* make tests green
Diffstat (limited to 'tests/arc')
-rw-r--r--tests/arc/topt_cursor2.nim51
-rw-r--r--tests/arc/topt_no_cursor.nim13
2 files changed, 59 insertions, 5 deletions
diff --git a/tests/arc/topt_cursor2.nim b/tests/arc/topt_cursor2.nim
new file mode 100644
index 000000000..2e6fb256f
--- /dev/null
+++ b/tests/arc/topt_cursor2.nim
@@ -0,0 +1,51 @@
+discard """
+  output: '''emptyemptyempty'''
+  cmd: '''nim c --gc:arc $file'''
+"""
+
+# bug #15039
+
+import lists
+
+type
+  Token = ref object of RootObj
+    children: DoublyLinkedList[Token]
+
+  Paragraph = ref object of Token
+
+method `$`(token: Token): string {.base.} =
+  result = "empty"
+
+method `$`(token: Paragraph): string =
+  if token.children.head == nil:
+    result = ""
+  else:
+    for c in token.children:
+      result.add $c
+
+proc parseLeafBlockInlines(token: Token) =
+  token.children.append(Token())
+  token.children.append(Token()) # <-- this one AAA
+
+  var emNode = newDoublyLinkedNode(Token())
+  var i = 0
+
+  var it = token.children.head
+  while it != nil:
+    var nxt = it.next  # this is not a cursor, it takes over ownership.
+    var childNode = it
+    if i == 0:
+      childNode.next = emNode # frees the object allocated in line 29 marked with AAA
+    elif i == 1:
+      emNode.next = childNode  #
+    it = nxt # incref on freed data, 'nxt' is freed
+    inc i
+
+proc parse() =
+  var token = Token()
+  token.children.append Paragraph()
+  parseLeafBlockInlines(token.children.head.value)
+  for children in token.children:
+    echo children
+
+parse()
diff --git a/tests/arc/topt_no_cursor.nim b/tests/arc/topt_no_cursor.nim
index e50418671..3ea4deaf1 100644
--- a/tests/arc/topt_no_cursor.nim
+++ b/tests/arc/topt_no_cursor.nim
@@ -29,11 +29,14 @@ result = (
 -- end of expandArc ------------------------
 --expandArc: delete
 
-var saved
-var sibling_cursor = target.parent.left
-`=`(saved, sibling_cursor.right)
-`=`(sibling_cursor.right, saved.left)
-`=sink`(sibling_cursor.parent, saved)
+var
+  sibling
+  saved
+`=`(sibling, target.parent.left)
+`=`(saved, sibling.right)
+`=`(sibling.right, saved.left)
+`=sink`(sibling.parent, saved)
+`=destroy`(sibling)
 -- end of expandArc ------------------------'''
 """