diff options
| author | 2026-10-15 02:35:44 +0330 | |
|---|---|---|
| committer | 2026-10-15 02:40:51 +0330 | |
| commit | 3de6ae4a6a74b2c4fa14c3f2d6fbfff3bb83c5f5 (patch) | |
| tree | 577ac1025bb02a11069cf288a38bfc5120e8402d /tests | |
| parent | destructors: 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')
| -rw-r--r-- | tests/conformance/6-ownership/drop_elements_pop_ok.zc | 12 | ||||
| -rw-r--r-- | tests/conformance/6-ownership/drop_no_move_out_child.zc | 12 | ||||
| -rw-r--r-- | tests/conformance/6-ownership/drop_no_move_out_field.zc | 13 | ||||
| -rw-r--r-- | tests/conformance/6-ownership/drop_no_move_out_pop.zc | 11 | ||||
| -rw-r--r-- | tests/xref.baseline | 1 |
5 files changed, 49 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 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 diff --git a/tests/conformance/6-ownership/drop_no_move_out_field.zc b/tests/conformance/6-ownership/drop_no_move_out_field.zc new file mode 100644 index 0000000..e4d863c --- /dev/null +++ b/tests/conformance/6-ownership/drop_no_move_out_field.zc @@ -0,0 +1,13 @@ +// expect error: b: can't move out of a value with drop +// destructors 6.15.5: an array that is a field of a value with a drop is part of it, so pop on it is refused too +include rt; +struct bag { int*[?] items; void drop() { rt.put_s("bag drop\n"); } } +fn main() { + bag* b = rt.new(bag); + b.items = rt.new(int*[?]); + int* x = rt.new(int); *x = 5; b.items.push(x); + int* y = b.items.pop(); + rt.put_n(*y); + return 0; +} +// zc0: skip diff --git a/tests/conformance/6-ownership/drop_no_move_out_pop.zc b/tests/conformance/6-ownership/drop_no_move_out_pop.zc new file mode 100644 index 0000000..3ee248f --- /dev/null +++ b/tests/conformance/6-ownership/drop_no_move_out_pop.zc @@ -0,0 +1,11 @@ +// expect error: a: can't move out of a value with drop +// destructors 6.15.5: pop moves an element out, so it is refused on an array with a drop, whose drop may need the element +include rt; +fn main() { + int*[?] a = drop(rt.new(int*[?]), fn() { rt.put_s("arr drop\n"); }); + int* x = rt.new(int); *x = 5; a.push(x); + int* y = a.pop(); + rt.put_n(*y); + return 0; +} +// zc0: skip diff --git a/tests/xref.baseline b/tests/xref.baseline index 1660302..e83798d 100644 --- a/tests/xref.baseline +++ b/tests/xref.baseline @@ -25,6 +25,7 @@ argowner args argowner_fact args argtemporary args arrloc arrvalue chk_reset +arrroot arrvalue asg_quiet assigncheck reassign_free asgcap reserve_assignment asm_fixes reserve_asm_references |
