summary refs log tree commit diff stats
path: root/tests/destructor/turn_destroy_into_finalizer.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/destructor/turn_destroy_into_finalizer.nim')
-rw-r--r--tests/destructor/turn_destroy_into_finalizer.nim26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/destructor/turn_destroy_into_finalizer.nim b/tests/destructor/turn_destroy_into_finalizer.nim
new file mode 100644
index 000000000..1409c1c57
--- /dev/null
+++ b/tests/destructor/turn_destroy_into_finalizer.nim
@@ -0,0 +1,26 @@
+discard """
+  output: "turn_destroy_into_finalizer works"
+  joinable: false
+"""
+
+type
+  Foo = object
+    id: int
+
+var destroyed: int
+
+proc `=destroy`(x: var Foo) =
+  #echo "finally ", x.id
+  inc destroyed
+
+proc main =
+  var r: ref Foo
+  for i in 1..50_000:
+    new(r)
+    r.id = i
+  if destroyed > 30_000:
+    echo "turn_destroy_into_finalizer works"
+  else:
+    echo "turn_destroy_into_finalizer failed: ", destroyed
+
+main()