aboutsummaryrefslogtreecommitdiff
path: root/tests/conformance
diff options
context:
space:
mode:
Diffstat (limited to 'tests/conformance')
-rw-r--r--tests/conformance/6-ownership/drop_elements_pop_ok.zc12
-rw-r--r--tests/conformance/6-ownership/drop_no_move_out_child.zc12
-rw-r--r--tests/conformance/6-ownership/drop_no_move_out_field.zc13
-rw-r--r--tests/conformance/6-ownership/drop_no_move_out_pop.zc11
4 files changed, 48 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