aboutsummaryrefslogtreecommitdiff
path: root/tests/conformance/6-ownership/drop_gc_cycle_long.zc
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 21:44:40 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 21:44:40 +0330
commitf3dcfd9805e1bd23b002f648d4391ec397122d9c (patch)
tree91acab7da09c9225a2d838791d70e5c2e7db54b9 /tests/conformance/6-ownership/drop_gc_cycle_long.zc
parentmerge work/small-oob: bytes test out-of-bounds read (diff)
parentexamples/actors_demo: print the fan-out replies in worker order, not arrival ... (diff)
merge work/known-bugs: constant-expression precedence, local const in constant expressions, duplicate case labels, unterminated strings, droppable cycles in one collection, js vm exit, docs, actors_demo orderHEADmain
Diffstat (limited to 'tests/conformance/6-ownership/drop_gc_cycle_long.zc')
-rw-r--r--tests/conformance/6-ownership/drop_gc_cycle_long.zc24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/conformance/6-ownership/drop_gc_cycle_long.zc b/tests/conformance/6-ownership/drop_gc_cycle_long.zc
new file mode 100644
index 0000000..3de3f1e
--- /dev/null
+++ b/tests/conformance/6-ownership/drop_gc_cycle_long.zc
@@ -0,0 +1,24 @@
+// expect: 0 5 15 5 0/
+// destructors 6.15.3: an unreachable cycle of five values with drops is finalized whole by one collection, each value once, then freed
+include rt;
+int n, sum;
+word g;
+struct node { node* next; int v; void drop() { n++; sum = sum + this.v; } }
+unchecked fn make() {
+ node* a = rt.new(node); node* p = a; int i;
+ a.v = 1;
+ for (i = 2; i <= 5; i++) { node* q = rt.new(node); q.v = i; p.next = q; p = q; }
+ p.next = a;
+ g = a;
+ return 0;
+}
+fn main() {
+ make();
+ rt.gc(); rt.put_n(n); rt.put_c(32);
+ g = 0;
+ rt.gc(); rt.put_n(n); rt.put_c(32); rt.put_n(sum); rt.put_c(32);
+ rt.gc(); rt.put_n(n); rt.put_c(32);
+ rt.put_n(rt.dcount); rt.put_c(10);
+ return 0;
+}
+// zc0: skip