diff options
| author | 2026-10-14 15:49:27 +0330 | |
|---|---|---|
| committer | 2026-10-14 15:49:27 +0330 | |
| commit | 0ff8e8ee280e46f9f0ff06bf0958e91ff29da52e (patch) | |
| tree | f0d8b760771ca31c9e15796c06ead330299ab8e6 /tests/conformance/6-ownership | |
| parent | agent/spec-conformance: unmerged work from previous session (diff) | |
conformance: port the previous agent's suite, fix six expectations, add sections 5 to 8 and appendix b, known.txt, zc0 skips, wire into test.sh
Diffstat (limited to 'tests/conformance/6-ownership')
31 files changed, 204 insertions, 0 deletions
diff --git a/tests/conformance/6-ownership/alias_after_free.zc b/tests/conformance/6-ownership/alias_after_free.zc new file mode 100644 index 0000000..56cc45e --- /dev/null +++ b/tests/conformance/6-ownership/alias_after_free.zc @@ -0,0 +1,7 @@ +// expect error: t: used after it was given away +// spec 6.6.3 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +char* tail(char* s) { return s + 1; } +fn main() { char* b = rt.new(4); b[0] = 97; b[1] = 98; b[2] = 0; char* t = tail(b); rt.free(b); rt.put_s(t); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/alias_before_free_ok.zc b/tests/conformance/6-ownership/alias_before_free_ok.zc new file mode 100644 index 0000000..cea455e --- /dev/null +++ b/tests/conformance/6-ownership/alias_before_free_ok.zc @@ -0,0 +1,7 @@ +// expect: b/ +// spec 6.6.3 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +char* tail(char* s) { return s + 1; } +fn main() { char* b = rt.new(4); b[0] = 97; b[1] = 98; b[2] = 0; char* t = tail(b); rt.put_s(t); rt.put_c(10); rt.free(b); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/array_literal_escape_global.zc b/tests/conformance/6-ownership/array_literal_escape_global.zc new file mode 100644 index 0000000..b5a9982 --- /dev/null +++ b/tests/conformance/6-ownership/array_literal_escape_global.zc @@ -0,0 +1,7 @@ +// expect error: an array literal cannot escape into a global or container +// spec 6.9.4 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int* g; +fn main() { g = (int[]){1, 2}; return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/block_value_m_rejected.zc b/tests/conformance/6-ownership/block_value_m_rejected.zc new file mode 100644 index 0000000..8cd8fe4 --- /dev/null +++ b/tests/conformance/6-ownership/block_value_m_rejected.zc @@ -0,0 +1,6 @@ +// expect error: p: has to be u to be handed up as the block's value +// spec 6.8.4 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* q = { int* p = rt.new(1); p }; pn(q[0]); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/block_value_u.zc b/tests/conformance/6-ownership/block_value_u.zc new file mode 100644 index 0000000..9cfd5df --- /dev/null +++ b/tests/conformance/6-ownership/block_value_u.zc @@ -0,0 +1,6 @@ +// expect: 4/ +// spec 6.8.4 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* q = { int* p = rt.new(1); p[0] = 4; u*p; p }; pn(q[0]); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/borrow_to_global.zc b/tests/conformance/6-ownership/borrow_to_global.zc new file mode 100644 index 0000000..2616c2d --- /dev/null +++ b/tests/conformance/6-ownership/borrow_to_global.zc @@ -0,0 +1,8 @@ +// expect error: p: is not an owner +// spec 6.9.1 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int* g; +void f(int*.m p) { g = p; } +fn main() { return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/container_child_freed.zc b/tests/conformance/6-ownership/container_child_freed.zc new file mode 100644 index 0000000..3611617 --- /dev/null +++ b/tests/conformance/6-ownership/container_child_freed.zc @@ -0,0 +1,8 @@ +// expect: 0/ +// spec 6.3.5 and 6.5.3 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +memdebug on; +struct n { int* c; } +fn main() { { n* a = rt.new(n); int* c = rt.new(1); c[0] = 1; a.c = c; pn(a.c[0] - 1); } rt.memreport(); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/copy_owner_rejected.zc b/tests/conformance/6-ownership/copy_owner_rejected.zc new file mode 100644 index 0000000..c102ac9 --- /dev/null +++ b/tests/conformance/6-ownership/copy_owner_rejected.zc @@ -0,0 +1,6 @@ +// expect error: p: is an owned object and can't be copied into another variable +// spec 6.8.5 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* p = rt.new(1); int* q; q = p; pn(q[0]); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/d_never_given_away.zc b/tests/conformance/6-ownership/d_never_given_away.zc new file mode 100644 index 0000000..a7167ff --- /dev/null +++ b/tests/conformance/6-ownership/d_never_given_away.zc @@ -0,0 +1,6 @@ +// expect error: p: d object was never given away +// spec 6.7 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* p = rt.new(2); p[0] = 1; d*p; return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/d_param_transfers.zc b/tests/conformance/6-ownership/d_param_transfers.zc new file mode 100644 index 0000000..78cc0e1 --- /dev/null +++ b/tests/conformance/6-ownership/d_param_transfers.zc @@ -0,0 +1,7 @@ +// expect error: q: used after it was given away +// spec 6.4 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +void take(int*.d p) { rt.free(p); } +fn main() { int* q = rt.new(int); take(q); pn(*q); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/free_then_reassign.zc b/tests/conformance/6-ownership/free_then_reassign.zc new file mode 100644 index 0000000..5ebc693 --- /dev/null +++ b/tests/conformance/6-ownership/free_then_reassign.zc @@ -0,0 +1,6 @@ +// expect: 7/ +// spec 6.8.5 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* a = rt.new(1); a[0] = 1; int* b = rt.new(1); b[0] = 7; rt.free(a); a = b; pn(a[0]); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/fresh_thrown_away.zc b/tests/conformance/6-ownership/fresh_thrown_away.zc new file mode 100644 index 0000000..9acec75 --- /dev/null +++ b/tests/conformance/6-ownership/fresh_thrown_away.zc @@ -0,0 +1,6 @@ +// expect error: a new object (or a u result) can't be thrown away +// spec 6.13 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { rt.new(2); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/global_store_needs_recast.zc b/tests/conformance/6-ownership/global_store_needs_recast.zc new file mode 100644 index 0000000..2b8d09a --- /dev/null +++ b/tests/conformance/6-ownership/global_store_needs_recast.zc @@ -0,0 +1,7 @@ +// expect: 2/ +// spec 6.9.1 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int* g; +fn main() { int* x = rt.new(1); x[0] = 2; g = d*x; pn(g[0]); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/global_store_then_use.zc b/tests/conformance/6-ownership/global_store_then_use.zc new file mode 100644 index 0000000..7aebc2c --- /dev/null +++ b/tests/conformance/6-ownership/global_store_then_use.zc @@ -0,0 +1,7 @@ +// expect error: x: used after it was given away +// spec 6.9.2 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int* g; +fn main() { int* x = rt.new(1); x[0] = 2; g = d*x; pn(x[0]); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/if_join_free_one_branch.zc b/tests/conformance/6-ownership/if_join_free_one_branch.zc new file mode 100644 index 0000000..77ccd23 --- /dev/null +++ b/tests/conformance/6-ownership/if_join_free_one_branch.zc @@ -0,0 +1,6 @@ +// expect: 1/ +// spec 6.10.1: dead on one path and m on the other becomes dead, freed on the live path +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* p = rt.new(1); p[0] = 1; if (p[0]) { pn(p[0]); rt.free(p); } return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/if_join_mismatch.zc b/tests/conformance/6-ownership/if_join_mismatch.zc new file mode 100644 index 0000000..f5c926f --- /dev/null +++ b/tests/conformance/6-ownership/if_join_mismatch.zc @@ -0,0 +1,6 @@ +// expect error: p: ends the branches of an if in different states +// spec 6.10.1 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* p = rt.new(1); p[0] = 1; int k = 1; if (k) { u*p; } else { pn(p[0]); } return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/lend_keeps_owner.zc b/tests/conformance/6-ownership/lend_keeps_owner.zc new file mode 100644 index 0000000..bb0813c --- /dev/null +++ b/tests/conformance/6-ownership/lend_keeps_owner.zc @@ -0,0 +1,7 @@ +// expect: 3/3/ +// spec 6.6.2 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +void show(int* p) { pn(*p); } +fn main() { int* q = rt.new(int); *q = 3; show(q); show(q); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/lend_to_global.zc b/tests/conformance/6-ownership/lend_to_global.zc new file mode 100644 index 0000000..8cd2b8d --- /dev/null +++ b/tests/conformance/6-ownership/lend_to_global.zc @@ -0,0 +1,8 @@ +// expect: 5/5/ +// spec 6.11 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int* g; +fn show() { pn(g[0]); return 0; } +fn main() { int* x = rt.new(1); x[0] = 5; int* saved = g; g = m*x; show(); g = saved; pn(x[0]); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/lend_to_global_open.zc b/tests/conformance/6-ownership/lend_to_global_open.zc new file mode 100644 index 0000000..7ef3a2b --- /dev/null +++ b/tests/conformance/6-ownership/lend_to_global_open.zc @@ -0,0 +1,7 @@ +// expect error: x: is lent to global g +// spec 6.11 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int* g; +fn main() { int* x = rt.new(1); x[0] = 5; g = m*x; return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/loop_give_away.zc b/tests/conformance/6-ownership/loop_give_away.zc new file mode 100644 index 0000000..6c1d385 --- /dev/null +++ b/tests/conformance/6-ownership/loop_give_away.zc @@ -0,0 +1,6 @@ +// expect error: p: is given away inside a loop that comes back around to it +// spec 6.10.2 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* p = rt.new(1); p[0] = 1; for (int i = 0; i < 2; i++) { rt.free(p); } return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/loop_give_away_break_ok.zc b/tests/conformance/6-ownership/loop_give_away_break_ok.zc new file mode 100644 index 0000000..e0d45ad --- /dev/null +++ b/tests/conformance/6-ownership/loop_give_away_break_ok.zc @@ -0,0 +1,6 @@ +// expect: 1/ +// spec 6.10.2 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* p = rt.new(1); p[0] = 1; while (1) { pn(p[0]); rt.free(p); break; } return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/m_freed_at_block_end_report.zc b/tests/conformance/6-ownership/m_freed_at_block_end_report.zc new file mode 100644 index 0000000..3466e4a --- /dev/null +++ b/tests/conformance/6-ownership/m_freed_at_block_end_report.zc @@ -0,0 +1,7 @@ +// expect: 0/ +// spec 6.5.1 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +memdebug on; +fn main() { { int* p = rt.new(3); p[0] = 1; pn(p[0] - 1); } rt.memreport(); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/never_used.zc b/tests/conformance/6-ownership/never_used.zc new file mode 100644 index 0000000..d4434bd --- /dev/null +++ b/tests/conformance/6-ownership/never_used.zc @@ -0,0 +1,6 @@ +// expect error: p: owned object is never used +// spec 6.5.2 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* p = rt.new(3); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/overwrite_leaks.zc b/tests/conformance/6-ownership/overwrite_leaks.zc new file mode 100644 index 0000000..a9b0138 --- /dev/null +++ b/tests/conformance/6-ownership/overwrite_leaks.zc @@ -0,0 +1,6 @@ +// expect error: a: still owns an object; overwriting it would leak it +// spec 6.8.5 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* a = rt.new(1); a[0] = 1; a = rt.new(1); pn(a[0]); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/recast_back_to_m.zc b/tests/conformance/6-ownership/recast_back_to_m.zc new file mode 100644 index 0000000..5784945 --- /dev/null +++ b/tests/conformance/6-ownership/recast_back_to_m.zc @@ -0,0 +1,7 @@ +// expect error: p: can't be recast back to m +// spec 6.7 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int* g; +fn main() { int* p = rt.new(2); d*p; m*p; g = p; return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/recast_nothing.zc b/tests/conformance/6-ownership/recast_nothing.zc new file mode 100644 index 0000000..e458a5f --- /dev/null +++ b/tests/conformance/6-ownership/recast_nothing.zc @@ -0,0 +1,6 @@ +// expect error: x: isn't an owned object, so there is no ownership to recast +// spec 6.7 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int x = 3; int* y = d*x; return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/return_owned_infers.zc b/tests/conformance/6-ownership/return_owned_infers.zc new file mode 100644 index 0000000..ad40b78 --- /dev/null +++ b/tests/conformance/6-ownership/return_owned_infers.zc @@ -0,0 +1,7 @@ +// expect: 5/ +// spec 6.8.3 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn make() { int* p = rt.new(1); p[0] = 5; return p; } +fn main() { int* q = make(); pn(q[0]); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/temporary_to_reader.zc b/tests/conformance/6-ownership/temporary_to_reader.zc new file mode 100644 index 0000000..b45d096 --- /dev/null +++ b/tests/conformance/6-ownership/temporary_to_reader.zc @@ -0,0 +1,7 @@ +// expect: abc/ +// spec 6.5.4 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +char* msg() { char* s = rt.new(4); s[0] = 97; s[1] = 98; s[2] = 99; s[3] = 0; return s; } +fn main() { rt.put_s(msg()); rt.put_c(10); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/u_must_leave.zc b/tests/conformance/6-ownership/u_must_leave.zc new file mode 100644 index 0000000..147d64f --- /dev/null +++ b/tests/conformance/6-ownership/u_must_leave.zc @@ -0,0 +1,6 @@ +// expect error: p: u object must leave this block +// spec 6.7 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* p = rt.new(2); p[0] = 1; u*p; return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/unchecked_no_errors.zc b/tests/conformance/6-ownership/unchecked_no_errors.zc new file mode 100644 index 0000000..2e4af57 --- /dev/null +++ b/tests/conformance/6-ownership/unchecked_no_errors.zc @@ -0,0 +1,6 @@ +// expect: 1/ +// spec 6.12 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +unchecked fn main() { int* p = rt.new(1); p[0] = 1; pn(p[0]); return 0; } +// zc0: skip diff --git a/tests/conformance/6-ownership/use_after_free.zc b/tests/conformance/6-ownership/use_after_free.zc new file mode 100644 index 0000000..ff3c113 --- /dev/null +++ b/tests/conformance/6-ownership/use_after_free.zc @@ -0,0 +1,6 @@ +// expect error: p: used after it was given away +// spec 6.5.1 +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +fn main() { int* p = rt.new(3); rt.free(p); pn(p[0]); return 0; } +// zc0: skip |
