aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 15:02:33 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 15:02:33 +0330
commit0c047b14a6488c4bda405cead225b7a700647c1a (patch)
treee34415841ca1c9b5c584976b06438ab13e4c6e26 /tests
parentanalyzer: a .u (declared or inferred) function can't return a borrowed parame... (diff)
tests: alias_scope expects the block-end message; plain_return now covers a forwarding owned return called early; direct owned return before its body is accepted
Diffstat (limited to 'tests')
-rw-r--r--tests/conformance/6-ownership/infer_owned_return_before_body.zc8
-rw-r--r--tests/errors/alias_scope.zc2
-rw-r--r--tests/errors/plain_return.zc5
3 files changed, 12 insertions, 3 deletions
diff --git a/tests/conformance/6-ownership/infer_owned_return_before_body.zc b/tests/conformance/6-ownership/infer_owned_return_before_body.zc
new file mode 100644
index 0000000..8db6b45
--- /dev/null
+++ b/tests/conformance/6-ownership/infer_owned_return_before_body.zc
@@ -0,0 +1,8 @@
+// expect: 5/0/
+// spec 6.8
+include rt;
+memdebug on;
+int use() { int* q = mk(); int v = *q; return v; }
+int* mk() { int* p = rt.new(int); *p = 5; return p; }
+fn main() { rt.put_n(use()); rt.put_c(10); rt.put_n(rt.memreport()); rt.put_c(10); }
+// zc0: skip
diff --git a/tests/errors/alias_scope.zc b/tests/errors/alias_scope.zc
index b52bfa8..ee56075 100644
--- a/tests/errors/alias_scope.zc
+++ b/tests/errors/alias_scope.zc
@@ -1,7 +1,7 @@
namespace;
include rt;
-// expect: q: used after it was given away
+// expect: q: borrows from p, which was freed at the end of its block
fn main() {
let q;
{ let p = rt.new(2); q = p + 0; }
diff --git a/tests/errors/plain_return.zc b/tests/errors/plain_return.zc
index c44c533..723ab98 100644
--- a/tests/errors/plain_return.zc
+++ b/tests/errors/plain_return.zc
@@ -2,5 +2,6 @@ namespace;
include rt;
// expect: is called before its body, so its owned return can't be known there
-fn main() { return mk(); }
-fn mk() { return rt.new(1); }
+int* mk() { int* p = rt.new(int); return p; }
+fn main() { return forward(); }
+int* forward() { return mk(); }