aboutsummaryrefslogtreecommitdiff
path: root/tests/errors/borrows_decl.zc
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 09:56:19 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 09:56:19 +0330
commit6bbac2edf7c50dac4d755a364b6dfd16471284d7 (patch)
treee83b493f55ed07287cd2ab4e3a940c04871d9a14 /tests/errors/borrows_decl.zc
parentanalyzer: use-after-end messages name the borrower, the owner and how the own... (diff)
analyzer: check borrow returns of forward-called functions at the unit's end; borrows clause for prototypes, definitions, externs and function types, checked against the body
Diffstat (limited to 'tests/errors/borrows_decl.zc')
-rw-r--r--tests/errors/borrows_decl.zc14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/errors/borrows_decl.zc b/tests/errors/borrows_decl.zc
new file mode 100644
index 0000000..5229979
--- /dev/null
+++ b/tests/errors/borrows_decl.zc
@@ -0,0 +1,14 @@
+namespace;
+include rt;
+
+// expect: r: used after it was given away; r borrows t, and t was freed on line 11 (t declared on line 8)
+// a prototype's borrows clause ties the result to the first argument's owner only.
+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); rt.put_c(r[0]);
+ return 0;
+}
+char* first(char* a, char* b) { return a; }