From 3de6ae4a6a74b2c4fa14c3f2d6fbfff3bb83c5f5 Mon Sep 17 00:00:00 2001 From: zinc Date: Thu, 15 Oct 2026 02:35:44 +0330 Subject: 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 --- tests/conformance/6-ownership/drop_no_move_out_child.zc | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/conformance/6-ownership/drop_no_move_out_child.zc (limited to 'tests/conformance/6-ownership/drop_no_move_out_child.zc') diff --git a/tests/conformance/6-ownership/drop_no_move_out_child.zc b/tests/conformance/6-ownership/drop_no_move_out_child.zc new file mode 100644 index 0000000..ca4a1c9 --- /dev/null +++ b/tests/conformance/6-ownership/drop_no_move_out_child.zc @@ -0,0 +1,12 @@ +// expect error: a borrowed projection cannot transfer ownership; transfer its owner +// destructors 6.15.5: a child of a value with a drop can be borrowed but not given away +include rt; +struct node { node* next; int v; void drop() { rt.put_s("drop "); rt.put_n(this.v); } } +int eat(node*.d n) { rt.put_n(n.v); return 0; } +fn main() { + node* a = rt.new(node); a.v = 1; + a.next = rt.new(node); a.next.v = 2; + eat(a.next); + return 0; +} +// zc0: skip -- cgit v1.2.3