summary refs log tree commit diff stats
path: root/tests/arc
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-06-04 14:37:58 +0800
committerGitHub <noreply@github.com>2023-06-04 08:37:58 +0200
commit929cb4d6017455b1749d2e3d7d1d903046f66163 (patch)
treed7a1e2fbd6815b060acc3e851ebe1d14e18a2055 /tests/arc
parent25fe4124e66dd44a10609d531081e650e3d557aa (diff)
downloadNim-929cb4d6017455b1749d2e3d7d1d903046f66163.tar.gz
fixes #21987; don't create type bound ops for anything in a function with a `nodestroy` pragma (#21992)
* fixes #21987; don't create type bound ops for anything in a function with a `nodestroy` pragma

* add a comment
Diffstat (limited to 'tests/arc')
-rw-r--r--tests/arc/tarc_orc.nim48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/arc/tarc_orc.nim b/tests/arc/tarc_orc.nim
index 387baa28f..594950d71 100644
--- a/tests/arc/tarc_orc.nim
+++ b/tests/arc/tarc_orc.nim
@@ -89,3 +89,51 @@ block: # bug #21974
   var a = newTest[X]()
   a.push((1, "One"))
   doAssert a.pop.value == "One"
+
+# bug #21987
+
+type
+  EmbeddedImage* = distinct Image
+  Image = object
+    len: int
+
+proc imageCopy*(image: Image): Image {.nodestroy.}
+
+proc `=destroy`*(x: var Image) =
+  discard
+proc `=sink`*(dest: var Image; source: Image) =
+  `=destroy`(dest)
+  wasMoved(dest)
+
+proc `=dup`*(source: Image): Image {.nodestroy.} =
+  result = imageCopy(source)
+
+proc `=copy`*(dest: var Image; source: Image) =
+  dest = imageCopy(source) # calls =sink implicitly
+
+proc `=destroy`*(x: var EmbeddedImage) = discard
+
+proc `=dup`*(source: EmbeddedImage): EmbeddedImage {.nodestroy.} = source
+
+proc `=copy`*(dest: var EmbeddedImage; source: EmbeddedImage) {.nodestroy.} =
+  dest = source
+
+proc imageCopy*(image: Image): Image =
+  result = image
+
+proc main2 =
+  block:
+    var a = Image(len: 2).EmbeddedImage
+    var b = Image(len: 1).EmbeddedImage
+    b = a
+    doAssert Image(a).len == 2
+    doAssert Image(b).len == 2
+
+  block:
+    var a = Image(len: 2)
+    var b = Image(len: 1)
+    b = a
+    doAssert a.len == 2
+    doAssert b.len == 0
+
+main2()
\ No newline at end of file