aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/borrows_clause.zc
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 11:29:26 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 11:29:26 +0330
commita3f769ea02b5686084c5b3c2a382b9934b535050 (patch)
tree47caed7e1bc49dbb9ee7aecd76f88c2048963f21 /tests/programs/borrows_clause.zc
parentmerge work/stdio: std.Io and one-level module completion (diff)
parentxref: baseline records the borrow globals (end_why, end_whom, arg_site, local... (diff)
merge work/borrow: borrow returns before definition, borrows clause, borrow messages and LSP diagnostics, mkgenome header mismatch values
Diffstat (limited to 'tests/programs/borrows_clause.zc')
-rw-r--r--tests/programs/borrows_clause.zc11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/programs/borrows_clause.zc b/tests/programs/borrows_clause.zc
new file mode 100644
index 0000000..6f43581
--- /dev/null
+++ b/tests/programs/borrows_clause.zc
@@ -0,0 +1,11 @@
+namespace;
+include rt;
+// a borrows clause on a prototype and its definition: freeing the other argument keeps the result.
+char* first(char* a, char* b) borrows a;
+fn main() {
+ char* t = rt.new(4); t[0] = 'x'; t[1] = 0;
+ char* u = rt.new(4); u[0] = 'y'; u[1] = 0;
+ let r = first(t, u); rt.free(u); rt.put_c(r[0]); rt.free(t);
+ return 0;
+}
+char* first(char* a, char* b) borrows a { return a; }