aboutsummaryrefslogtreecommitdiff
path: root/tests/conformance/6-ownership/drop_elements_pop_ok.zc
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 02:35:44 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 02:40:51 +0330
commit3de6ae4a6a74b2c4fa14c3f2d6fbfff3bb83c5f5 (patch)
tree577ac1025bb02a11069cf288a38bfc5120e8402d /tests/conformance/6-ownership/drop_elements_pop_ok.zc
parentdestructors: reassigning an m owner that still holds a value frees the old va... (diff)
destructors: nothing moves out of a value with a drop: pop on an array with a drop, or on an array field of a value with a drop, is error: a: can't move out of a value with drop (fields were already borrowed projections); spec 6.15.5, four conformance programs
Diffstat (limited to 'tests/conformance/6-ownership/drop_elements_pop_ok.zc')
-rw-r--r--tests/conformance/6-ownership/drop_elements_pop_ok.zc12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/conformance/6-ownership/drop_elements_pop_ok.zc b/tests/conformance/6-ownership/drop_elements_pop_ok.zc
new file mode 100644
index 0000000..9c97e44
--- /dev/null
+++ b/tests/conformance/6-ownership/drop_elements_pop_ok.zc
@@ -0,0 +1,12 @@
+// expect: 5 drop5 after
+// destructors 6.15.5: an array without a drop can hand out a droppable element; pop gives it to the new owner, whose block end drops it
+include rt;
+struct node { int v; void drop() { rt.put_s("drop"); rt.put_n(this.v); rt.put_s(" "); } }
+fn main() {
+ node*[?] a = rt.new(node*[?]);
+ node* x = rt.new(node); x.v = 5; a.push(x);
+ { node* y = a.pop(); rt.put_n(y.v); rt.put_s(" "); }
+ rt.put_s("after ");
+ return 0;
+}
+// zc0: skip