aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conformance/6-ownership/infer_owned_return_discarded.zc7
-rw-r--r--tests/conformance/6-ownership/infer_owned_return_recursive.zc21
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/conformance/6-ownership/infer_owned_return_discarded.zc b/tests/conformance/6-ownership/infer_owned_return_discarded.zc
new file mode 100644
index 0000000..33d51a7
--- /dev/null
+++ b/tests/conformance/6-ownership/infer_owned_return_discarded.zc
@@ -0,0 +1,7 @@
+// expect error: a new object (or a u result) can't be thrown away
+// spec 6.8
+include rt;
+struct node { int value; node* next; };
+node* make() { node* n = rt.new(node); return n; }
+fn main() { make(); }
+// zc0: skip
diff --git a/tests/conformance/6-ownership/infer_owned_return_recursive.zc b/tests/conformance/6-ownership/infer_owned_return_recursive.zc
new file mode 100644
index 0000000..1299f64
--- /dev/null
+++ b/tests/conformance/6-ownership/infer_owned_return_recursive.zc
@@ -0,0 +1,21 @@
+// expect: 1/0/
+// spec 6.8
+include rt;
+memdebug on;
+struct node { int value; node* next; };
+node* make_list(int count) {
+ node* head = rt.new(node);
+ head.value = count;
+ if (count > 1) head.next = make_list(count - 1);
+ return head;
+}
+node* last(node* list) {
+ node* cursor = list;
+ while (cursor.next) cursor = cursor.next;
+ return cursor;
+}
+fn main() {
+ { node* list = make_list(4); rt.put_n(last(list).value); rt.put_c(10); }
+ rt.put_n(rt.memreport()); rt.put_c(10);
+}
+// zc0: skip