diff options
| author | 2026-10-14 05:55:19 +0000 | |
|---|---|---|
| committer | 2026-10-14 05:55:19 +0000 | |
| commit | 05f7b7e09ad503e4eac4f757de0d7329174f6437 (patch) | |
| tree | 768931192a69eff878d8f149c418fff55b0fdf8e /tests/errors | |
| parent | docs: archive the frozen stage code as one compressed tarball (diff) | |
analyzer: close the ownership gaps that stopped the compiler compiling itself
an owned local can now move into a released owner declared in the same or an
outer block, and g = m*x lends a local owner to a global until the global is
assigned again in the same block. leaving that block, giving the local away, or
returning while the lend is open is an error. recasting a plain local now names
it and says it has no ownership to recast.
methdef and syntax_resident use the supported spellings, so make genome reaches
its fixpoint from a clean checkout. runerr.sh reads the first // expect: line,
since the include headers moved it off line 1.
Diffstat (limited to 'tests/errors')
| -rw-r--r-- | tests/errors/lend_branch.zc | 6 | ||||
| -rw-r--r-- | tests/errors/lend_give.zc | 6 | ||||
| -rw-r--r-- | tests/errors/lend_return.zc | 6 | ||||
| -rw-r--r-- | tests/errors/lend_unrestored.zc | 6 | ||||
| -rw-r--r-- | tests/errors/move_live_owner.zc | 5 | ||||
| -rw-r--r-- | tests/errors/recast_plain.zc | 6 | ||||
| -rw-r--r-- | tests/errors/unused.zc | 2 |
7 files changed, 36 insertions, 1 deletions
diff --git a/tests/errors/lend_branch.zc b/tests/errors/lend_branch.zc new file mode 100644 index 0000000..594047f --- /dev/null +++ b/tests/errors/lend_branch.zc @@ -0,0 +1,6 @@ +namespace; +include rt; + +// expect: buf: is lent to global sink; assign the global again before the block that lent it ends +word sink; +fn main() { word buf = rt.new(4); sink = m*buf; if (buf[0]) { sink = 0; } return 0; } diff --git a/tests/errors/lend_give.zc b/tests/errors/lend_give.zc new file mode 100644 index 0000000..2fd2f5b --- /dev/null +++ b/tests/errors/lend_give.zc @@ -0,0 +1,6 @@ +namespace; +include rt; + +// expect: buf: is lent to global sink; assign the global again before giving the local away +word sink; +fn main() { word buf = rt.new(4); sink = m*buf; rt.free(buf); sink = 0; return 0; } diff --git a/tests/errors/lend_return.zc b/tests/errors/lend_return.zc new file mode 100644 index 0000000..b0c4b53 --- /dev/null +++ b/tests/errors/lend_return.zc @@ -0,0 +1,6 @@ +namespace; +include rt; + +// expect: buf: is lent to global sink; assign the global again before the block that lent it ends +word sink; +fn main() { word buf = rt.new(4); sink = m*buf; if (buf[0]) return 1; sink = 0; return 0; } diff --git a/tests/errors/lend_unrestored.zc b/tests/errors/lend_unrestored.zc new file mode 100644 index 0000000..1b316df --- /dev/null +++ b/tests/errors/lend_unrestored.zc @@ -0,0 +1,6 @@ +namespace; +include rt; + +// expect: buf: is lent to global sink; assign the global again before the block that lent it ends +word sink; +fn main() { word buf = rt.new(4); sink = m*buf; buf[0] = 1; return 0; } diff --git a/tests/errors/move_live_owner.zc b/tests/errors/move_live_owner.zc new file mode 100644 index 0000000..e36909c --- /dev/null +++ b/tests/errors/move_live_owner.zc @@ -0,0 +1,5 @@ +namespace; +include rt; + +// expect: still owns an object; overwriting it would leak it +fn main() { word r = rt.new(4); { word n = rt.new(8); n[0] = 1; r = n; } r[0] = 2; return 0; } diff --git a/tests/errors/recast_plain.zc b/tests/errors/recast_plain.zc new file mode 100644 index 0000000..7d26f3c --- /dev/null +++ b/tests/errors/recast_plain.zc @@ -0,0 +1,6 @@ +namespace; +include rt; + +// expect: p: isn't an owned object, so there is no ownership to recast +word sink; +fn main() { word p = m*rt.new(4); sink = d*p; return 0; } diff --git a/tests/errors/unused.zc b/tests/errors/unused.zc index 5c88ce3..7a1c7e4 100644 --- a/tests/errors/unused.zc +++ b/tests/errors/unused.zc @@ -1,5 +1,5 @@ namespace; include rt; -// expect: x is never read +// expect: x: owned object is never used fn main() { let x = rt.new(3); return 0; } |
