summary refs log tree commit diff stats
path: root/tests/destructor/tdestructor3.nim
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2020-10-22 13:23:39 +0200
committerGitHub <noreply@github.com>2020-10-22 13:23:39 +0200
commit7435d912adcf411feed4ba124808527c7e04a44f (patch)
tree9ba7b009a510edfbcf49c0a0ec87543548aae2d5 /tests/destructor/tdestructor3.nim
parent7c359a062c17696aab5dd5b75d595af0596c001c (diff)
downloadNim-7435d912adcf411feed4ba124808527c7e04a44f.tar.gz
Add testcase for #14601 (#15677)
Diffstat (limited to 'tests/destructor/tdestructor3.nim')
-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 ca9a891e1..eb49f3f15 100644
--- a/tests/destructor/tdestructor3.nim
+++ b/tests/destructor/tdestructor3.nim
@@ -127,4 +127,48 @@ proc test2() =
 echo "---------------"
 echo "app begin"
 test2()
-echo "app end"
\ No newline at end of file
+echo "app end"
+
+# bug #14601
+
+when true: # D20200607T202043
+  type Foo2 = object
+    x: int
+    x2: array[10, int]
+
+  type Vec = object
+    vals: seq[Foo2]
+
+  proc `=destroy`*(a: var Foo2) {.inline.} =
+    discard
+
+  proc initFoo2(x: int): Foo2 = Foo2(x: x)
+
+  proc add2(v: var Vec, a: Foo2) = # ditto with `a: sink Foo2`
+    v.vals.add a
+
+  proc add3(v: var Vec, a: Foo2) = # ditto with `a: sink Foo2`
+    v.vals = @[a]
+
+  proc add4(v: var Vec, a: sink Foo2) = # ditto with `a: sink Foo2`
+    v.vals.add a
+
+  proc add5(v: var Vec, a: sink Foo2) = # ditto with `a: sink Foo2`
+    v.vals = @[a]
+
+  proc main2()=
+    var a: Vec
+    var b = Foo2(x: 10)
+    a.add2 b # ok
+    a.vals.add Foo2(x: 10) # ok
+    a.add2 initFoo2(x = 10) # ok
+    a.add2 Foo2(x: 10) # bug
+    a.add3 initFoo2(x = 10) # ok
+    a.add3 Foo2(x: 10) # bug
+    a.add4 initFoo2(x = 10) # ok
+    a.add4 Foo2(x: 10) # bug
+    a.add5 initFoo2(x = 10) # ok
+    a.add5 Foo2(x: 10) # bug
+  main2()
+
+