summary refs log tree commit diff stats
path: root/tests/destructor/tmisc_destructors.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/destructor/tmisc_destructors.nim')
-rw-r--r--tests/destructor/tmisc_destructors.nim43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/destructor/tmisc_destructors.nim b/tests/destructor/tmisc_destructors.nim
new file mode 100644
index 000000000..082cb0f78
--- /dev/null
+++ b/tests/destructor/tmisc_destructors.nim
@@ -0,0 +1,43 @@
+discard """
+  output: '''@[0]
+@[1]
+@[2]
+@[3]'''
+  joinable: false
+"""
+
+# bug #6434
+
+type
+  Foo* = object
+    boo: int
+
+var sink_counter = 0
+var assign_counter = 0
+
+proc `=sink`(dest: var Foo, src: Foo) =
+  sink_counter.inc
+
+proc `=`(dest: var Foo, src: Foo) =
+  assign_counter.inc
+
+proc createFoo(): Foo = Foo(boo: 0)
+
+proc test(): auto =
+  var a, b = createFoo()
+  return (a, b, Foo(boo: 5))
+
+var (ag, bg, _) = test()
+
+doAssert assign_counter == 0
+doAssert sink_counter == 0
+
+# bug #11510
+proc main =
+  for i in 0 ..< 4:
+    var buffer: seq[int] # = @[] # uncomment to make it work
+    # var buffer: string # also this is broken
+    buffer.add i
+    echo buffer
+
+main()