diff options
| author | 2026-10-12 08:46:23 +0330 | |
|---|---|---|
| committer | 2026-10-12 08:46:23 +0330 | |
| commit | ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch) | |
| tree | 70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /docs/history/10-zc/code/tests/errors | |
a
Diffstat (limited to 'docs/history/10-zc/code/tests/errors')
24 files changed, 62 insertions, 0 deletions
diff --git a/docs/history/10-zc/code/tests/errors/back_to_m.zc b/docs/history/10-zc/code/tests/errors/back_to_m.zc new file mode 100644 index 0000000..ee25096 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/back_to_m.zc @@ -0,0 +1,2 @@ +// expect: x: can't be recast back to m +fn main() { var x = new(3); x as d; x as m; return 0; } diff --git a/docs/history/10-zc/code/tests/errors/borrow_escape.zc b/docs/history/10-zc/code/tests/errors/borrow_escape.zc new file mode 100644 index 0000000..725bc61 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/borrow_escape.zc @@ -0,0 +1,3 @@ +// expect: p: is owned and can't be returned +fn f(m p) { return p; } +fn main() { var x = new(1); f(x); return 0; } diff --git a/docs/history/10-zc/code/tests/errors/branch_mismatch.zc b/docs/history/10-zc/code/tests/errors/branch_mismatch.zc new file mode 100644 index 0000000..62cb18b --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/branch_mismatch.zc @@ -0,0 +1,3 @@ +// expect: x: ends the branches of an if in different states +fn take(d p) { return p[0]; } +fn main() { var x = new(1); x as d; if (x[0]) take(x); return 0; } diff --git a/docs/history/10-zc/code/tests/errors/child_dies.zc b/docs/history/10-zc/code/tests/errors/child_dies.zc new file mode 100644 index 0000000..16e1935 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/child_dies.zc @@ -0,0 +1,3 @@ +// expect: c: used after it was given away +fn take(d p) { return p[0]; } +fn main() { var p = new(2), c = new(1); p[0] = c; take(p as d); return c[0]; } diff --git a/docs/history/10-zc/code/tests/errors/child_recast.zc b/docs/history/10-zc/code/tests/errors/child_recast.zc new file mode 100644 index 0000000..f4be23e --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/child_recast.zc @@ -0,0 +1,2 @@ +// expect: c: belongs to a container; recast the container instead +fn main() { var p = new(2), c = new(1); p[0] = c; c as d; return 0; } diff --git a/docs/history/10-zc/code/tests/errors/copy_owned.zc b/docs/history/10-zc/code/tests/errors/copy_owned.zc new file mode 100644 index 0000000..42d2ab0 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/copy_owned.zc @@ -0,0 +1,2 @@ +// expect: x: is an owned object and can't be copied +fn main() { var x = new(1); var y = x; return y[0]; } diff --git a/docs/history/10-zc/code/tests/errors/d_into_block.zc b/docs/history/10-zc/code/tests/errors/d_into_block.zc new file mode 100644 index 0000000..02189ab --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/d_into_block.zc @@ -0,0 +1,2 @@ +// expect: x: used after it was given away +fn main() { var x = new(1); x as d; { x[0] = 5; } return x[0]; } diff --git a/docs/history/10-zc/code/tests/errors/d_kept.zc b/docs/history/10-zc/code/tests/errors/d_kept.zc new file mode 100644 index 0000000..28eaccf --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/d_kept.zc @@ -0,0 +1,2 @@ +// expect: x: d object was never given away +fn main() { var x = new(3); x as d; x[0] = 1; return 0; } diff --git a/docs/history/10-zc/code/tests/errors/discard_u.zc b/docs/history/10-zc/code/tests/errors/discard_u.zc new file mode 100644 index 0000000..18bc810 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/discard_u.zc @@ -0,0 +1,3 @@ +// expect: can't be thrown away +fn mk() -> u { var p = new(1); return p as u; } +fn main() { mk(); return 0; } diff --git a/docs/history/10-zc/code/tests/errors/give_m.zc b/docs/history/10-zc/code/tests/errors/give_m.zc new file mode 100644 index 0000000..537fa0c --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/give_m.zc @@ -0,0 +1,3 @@ +// expect: x: is m; write 'as d' +fn take(d p) { return p[0]; } +fn main() { var x = new(3); take(x); return 0; } diff --git a/docs/history/10-zc/code/tests/errors/global_store.zc b/docs/history/10-zc/code/tests/errors/global_store.zc new file mode 100644 index 0000000..13882b9 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/global_store.zc @@ -0,0 +1,3 @@ +// expect: x: must be d to be stored in a global +var g; +fn main() { var x = new(1); g = x; return 0; } diff --git a/docs/history/10-zc/code/tests/errors/leak_overwrite.zc b/docs/history/10-zc/code/tests/errors/leak_overwrite.zc new file mode 100644 index 0000000..42773fb --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/leak_overwrite.zc @@ -0,0 +1,2 @@ +// expect: x: still owns an object +fn main() { var x = new(1); x = new(2); return x[0]; } diff --git a/docs/history/10-zc/code/tests/errors/lend_d.zc b/docs/history/10-zc/code/tests/errors/lend_d.zc new file mode 100644 index 0000000..e1e37d5 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/lend_d.zc @@ -0,0 +1,4 @@ +// expect: x: is d; pass it to a d parameter +fn look(m p) { return p[0]; } +fn take(d p) { return p[0]; } +fn main() { var x = new(3); x as d; look(x); take(x); return 0; } diff --git a/docs/history/10-zc/code/tests/errors/loop_move.zc b/docs/history/10-zc/code/tests/errors/loop_move.zc new file mode 100644 index 0000000..b1a6019 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/loop_move.zc @@ -0,0 +1,3 @@ +// expect: x: changes state inside a loop +fn take(d p) { return p[0]; } +fn main() { var x = new(1); var i = 0; x as d; while (i < 3) { take(x); i++; } return 0; } diff --git a/docs/history/10-zc/code/tests/errors/plain_return.zc b/docs/history/10-zc/code/tests/errors/plain_return.zc new file mode 100644 index 0000000..61f546f --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/plain_return.zc @@ -0,0 +1,3 @@ +// expect: returns a new object; declare the function with -> u +fn mk() { return new(1); } +fn main() { return mk(); } diff --git a/docs/history/10-zc/code/tests/errors/proto_needed.zc b/docs/history/10-zc/code/tests/errors/proto_needed.zc new file mode 100644 index 0000000..2613b9d --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/proto_needed.zc @@ -0,0 +1,3 @@ +// expect: f: was called before its tags were declared +fn main() { var x = new(1); f(1); return x[0]; } +fn f(d p) { return 0; } diff --git a/docs/history/10-zc/code/tests/errors/return_m.zc b/docs/history/10-zc/code/tests/errors/return_m.zc new file mode 100644 index 0000000..c361760 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/return_m.zc @@ -0,0 +1,3 @@ +// expect: x: has to be u to be returned +fn mk() -> u { var x = new(1); return x; } +fn main() { var y = mk(); return y[0]; } diff --git a/docs/history/10-zc/code/tests/errors/tag_mismatch.zc b/docs/history/10-zc/code/tests/errors/tag_mismatch.zc new file mode 100644 index 0000000..f9631d6 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/tag_mismatch.zc @@ -0,0 +1,2 @@ +// expect: c: its tag doesn't match its container's +fn main() { var p = new(2), c = new(1); p as u; p[0] = c; return 0; } diff --git a/docs/history/10-zc/code/tests/errors/u_dropped.zc b/docs/history/10-zc/code/tests/errors/u_dropped.zc new file mode 100644 index 0000000..76b7765 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/u_dropped.zc @@ -0,0 +1,2 @@ +// expect: x: u object must leave this block +fn main() { var x = new(3); x as u; return 0; } diff --git a/docs/history/10-zc/code/tests/errors/u_skip_level.zc b/docs/history/10-zc/code/tests/errors/u_skip_level.zc new file mode 100644 index 0000000..b8a024f --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/u_skip_level.zc @@ -0,0 +1,2 @@ +// expect: t: is u; it can only be handed to a variable of the enclosing block +fn main() { var r; { { var t = new(1); t as u; r = t; } } return r[0]; } diff --git a/docs/history/10-zc/code/tests/errors/unchecked_touch.zc b/docs/history/10-zc/code/tests/errors/unchecked_touch.zc new file mode 100644 index 0000000..1f57466 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/unchecked_touch.zc @@ -0,0 +1,2 @@ +// expect: x: is tracked by the analyzer and can't be used in unchecked code +fn main() { var x = new(1); unchecked { x[0] = 1; } return 0; } diff --git a/docs/history/10-zc/code/tests/errors/untagged_param.zc b/docs/history/10-zc/code/tests/errors/untagged_param.zc new file mode 100644 index 0000000..5a044c6 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/untagged_param.zc @@ -0,0 +1,3 @@ +// expect: x: is an owned object; it can only be passed to an m or d parameter +fn f(p) { return 0; } +fn main() { var x = new(1); f(x); return 0; } diff --git a/docs/history/10-zc/code/tests/errors/unused.zc b/docs/history/10-zc/code/tests/errors/unused.zc new file mode 100644 index 0000000..cbc6129 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/unused.zc @@ -0,0 +1,2 @@ +// expect: x: m object is never used +fn main() { var x = new(3); return 0; } diff --git a/docs/history/10-zc/code/tests/errors/use_after_give.zc b/docs/history/10-zc/code/tests/errors/use_after_give.zc new file mode 100644 index 0000000..5225462 --- /dev/null +++ b/docs/history/10-zc/code/tests/errors/use_after_give.zc @@ -0,0 +1,3 @@ +// expect: x: used after it was given away +fn take(d p) { return p[0]; } +fn main() { var x = new(3); take(x as d); return x[0]; } |
