summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2019-06-19 17:39:52 +0200
committerAraq <rumpf_a@web.de>2019-06-19 17:39:52 +0200
commitab36ffbeb1bcb0154fa077a5616a3f5466dd5e37 (patch)
tree5f789f6592851c58c003fe0941024ded70220b4b /tests
parentff89f7e33a8b5886ad51fbcd2e7aa26ec860da98 (diff)
downloadNim-ab36ffbeb1bcb0154fa077a5616a3f5466dd5e37.tar.gz
[bugfix] fixes #11517
Diffstat (limited to 'tests')
-rw-r--r--tests/destructor/tdestructor3.nim46
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/destructor/tdestructor3.nim b/tests/destructor/tdestructor3.nim
index a1de284ae..4c251e0bf 100644
--- a/tests/destructor/tdestructor3.nim
+++ b/tests/destructor/tdestructor3.nim
@@ -5,7 +5,9 @@ destroy
 5
 123
 destroy Foo: 123
-destroy Foo: 5'''
+destroy Foo: 5
+(x1: (val: ...))
+destroy'''
 joinable: false
 """
 
@@ -49,3 +51,45 @@ proc main =
   test(toFooPtr(123))
 
 main()
+
+# bug #11517
+type
+  UniquePtr*[T] = object
+    val: ptr T
+
+proc `=destroy`*[T](p: var UniquePtr[T]) =
+  mixin `=destroy`
+  echo "destroy"
+  if p.val != nil:
+    `=destroy`(p.val[])
+    dealloc(p.val)
+    p.val = nil
+
+proc `=`*[T](dest: var UniquePtr[T], src: UniquePtr[T]) {.error.}
+
+proc `=sink`*[T](dest: var UniquePtr[T], src: UniquePtr[T]) {.inline.} =
+  if dest.val != src.val:
+    if dest.val != nil:
+      `=destroy`(dest)
+    dest.val = src.val
+
+proc newUniquePtr*[T](val: sink T): UniquePtr[T] =
+  result.val = create(T)
+  result.val[] = val
+
+#-------------------------------------------------------------
+
+type
+  MyObject = object of RootObj
+    x1: UniquePtr[int]
+
+  MyObject2 = object of MyObject
+
+proc newObj2(x:int, y: float): MyObject2 =
+  MyObject2(x1: newUniquePtr(x))
+
+proc test =
+  let obj2 = newObj2(1, 1.0)
+  echo obj2
+
+test()