aboutsummaryrefslogtreecommitdiff
path: root/tests/conformance
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 15:01:29 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 15:01:29 +0330
commit5aaf70abdda0026a7b4d647746a109d94b25f7a0 (patch)
tree6e2448d5133ed2afba58dc66762400827c890c3b /tests/conformance
parentstd.Io.print/println take any mix of printable arguments (compiler expands pe... (diff)
analyzer: a .u (declared or inferred) function can't return a borrowed parameter or a value derived from one; fixtures
Diffstat (limited to 'tests/conformance')
-rw-r--r--tests/conformance/6-ownership/infer_owned_return_borrow_first.zc10
-rw-r--r--tests/conformance/6-ownership/infer_owned_return_mixed.zc11
-rw-r--r--tests/conformance/6-ownership/u_return_param_field.zc7
-rw-r--r--tests/conformance/6-ownership/u_return_plain_param.zc8
4 files changed, 36 insertions, 0 deletions
diff --git a/tests/conformance/6-ownership/infer_owned_return_borrow_first.zc b/tests/conformance/6-ownership/infer_owned_return_borrow_first.zc
new file mode 100644
index 0000000..e75fb10
--- /dev/null
+++ b/tests/conformance/6-ownership/infer_owned_return_borrow_first.zc
@@ -0,0 +1,10 @@
+// expect error: a borrowed parameter cannot be returned as an owned result
+// spec 6.8
+include rt;
+struct node { int v; node* next; };
+node* pick(node* other, int which) {
+ if (which) return other;
+ return rt.new(node);
+}
+fn main() { }
+// zc0: skip
diff --git a/tests/conformance/6-ownership/infer_owned_return_mixed.zc b/tests/conformance/6-ownership/infer_owned_return_mixed.zc
new file mode 100644
index 0000000..5216003
--- /dev/null
+++ b/tests/conformance/6-ownership/infer_owned_return_mixed.zc
@@ -0,0 +1,11 @@
+// expect error: a borrowed parameter cannot be returned as an owned result
+// spec 6.8
+include rt;
+struct node { int value; node* next; };
+node* pick(node* other, int which) {
+ node* fresh = rt.new(node);
+ if (which) return fresh;
+ return other;
+}
+fn main() { node* a = rt.new(node); node* b = pick(a, 1); rt.put_n(b.value); }
+// zc0: skip
diff --git a/tests/conformance/6-ownership/u_return_param_field.zc b/tests/conformance/6-ownership/u_return_param_field.zc
new file mode 100644
index 0000000..af8284d
--- /dev/null
+++ b/tests/conformance/6-ownership/u_return_param_field.zc
@@ -0,0 +1,7 @@
+// expect error: a borrowed parameter cannot be returned as an owned result
+// spec 6.8
+include rt;
+struct node { int v; node* next; };
+node*.u nxt(node* l) { node* c = l.next; return c; }
+fn main() { }
+// zc0: skip
diff --git a/tests/conformance/6-ownership/u_return_plain_param.zc b/tests/conformance/6-ownership/u_return_plain_param.zc
new file mode 100644
index 0000000..5aca40b
--- /dev/null
+++ b/tests/conformance/6-ownership/u_return_plain_param.zc
@@ -0,0 +1,8 @@
+// expect error: a borrowed parameter cannot be returned as an owned result
+// spec 6.8
+include rt;
+memdebug on;
+struct node { int value; node* next; };
+node*.u pick(node* other) { return other; }
+fn main() { node* a = rt.new(node); { node* b = pick(a); rt.put_n(b.value); } rt.put_n(a.value); }
+// zc0: skip