From 6bbac2edf7c50dac4d755a364b6dfd16471284d7 Mon Sep 17 00:00:00 2001 From: zinc Date: Thu, 15 Oct 2026 09:56:19 +0330 Subject: 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 --- tests/programs/borrows_clause.zc | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/programs/borrows_clause.zc (limited to 'tests/programs/borrows_clause.zc') 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; } -- cgit v1.2.3