aboutsummaryrefslogtreecommitdiff
path: root/tests/conformance/6-ownership/borrow_outlives_block.zc
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 14:57:42 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 14:57:42 +0330
commit0432ac6aefccbc5a9af25bd4ed2d4451611c4ff4 (patch)
treeba312d92bc223e1a4c500134cf1343f7e1f63180 /tests/conformance/6-ownership/borrow_outlives_block.zc
parentmerge work/borrow: borrow returns before definition, borrows clause, borrow m... (diff)
analyzer: an outer owner moved into a deeper container can take it back (loop-built lists); block-end frees name the owner (why 9) in messages and LSP related info
Diffstat (limited to 'tests/conformance/6-ownership/borrow_outlives_block.zc')
-rw-r--r--tests/conformance/6-ownership/borrow_outlives_block.zc21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/conformance/6-ownership/borrow_outlives_block.zc b/tests/conformance/6-ownership/borrow_outlives_block.zc
new file mode 100644
index 0000000..4d9b44a
--- /dev/null
+++ b/tests/conformance/6-ownership/borrow_outlives_block.zc
@@ -0,0 +1,21 @@
+// expect error: second: borrows from head, which was freed at the end of its block (line 17)
+// spec 6.6.3
+include rt;
+
+struct node {
+ int value;
+ node* next;
+};
+
+fn main() {
+ node* second;
+ {
+ node* head = rt.new(node);
+ head.next = rt.new(node);
+ head.next.value = 1;
+ second = head.next;
+ }
+ rt.put_n(second.value);
+ rt.put_c(10);
+}
+// zc0: skip