aboutsummaryrefslogtreecommitdiff
path: root/tests/hold/reject
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 14:33:28 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 14:33:28 +0330
commit25aa655e5b9464e291d542081ed1cf0f8fd666af (patch)
treefb2fa4b3e77914ab00829b39142a2f8cfb3a9d8b /tests/hold/reject
parenthold blocks: top-level hold { shared let ...; fn ... } monitors; shared value... (diff)
hold: fixtures (accept, reject, race, rank order) and tests/drivers/hold_test.py
Diffstat (limited to 'tests/hold/reject')
-rw-r--r--tests/hold/reject/actor_handler.zc8
-rw-r--r--tests/hold/reject/closure.zc5
-rw-r--r--tests/hold/reject/nested.zc5
-rw-r--r--tests/hold/reject/o3.zc5
-rw-r--r--tests/hold/reject/order.zc7
-rw-r--r--tests/hold/reject/outside.zc5
-rw-r--r--tests/hold/reject/pointer.zc5
7 files changed, 40 insertions, 0 deletions
diff --git a/tests/hold/reject/actor_handler.zc b/tests/hold/reject/actor_handler.zc
new file mode 100644
index 0000000..5548cad
--- /dev/null
+++ b/tests/hold/reject/actor_handler.zc
@@ -0,0 +1,8 @@
+// error: total: is shared in a hold block; only the functions written inside that block can use it
+// shared state reached from an actor's handler without going through its hold block
+namespace;
+include rt, actor;
+typecheck on;
+hold { shared let total; fn add(int n) { total = total + n; return total; } }
+int work(int n) { total = total + n; return n; }
+fn main() { actor.Actor<int,int>* a = rt.new(actor.Actor<int,int>); a.spawn(work); a.send(1); a.close(); return 0; }
diff --git a/tests/hold/reject/closure.zc b/tests/hold/reject/closure.zc
new file mode 100644
index 0000000..5c082d2
--- /dev/null
+++ b/tests/hold/reject/closure.zc
@@ -0,0 +1,5 @@
+// error: c: is shared; a closure can't use it
+namespace;
+include rt;
+hold { shared let c; fn a() { let f = fn() { return c; }; return f(); } }
+fn main() { return a(); }
diff --git a/tests/hold/reject/nested.zc b/tests/hold/reject/nested.zc
new file mode 100644
index 0000000..b8d38a6
--- /dev/null
+++ b/tests/hold/reject/nested.zc
@@ -0,0 +1,5 @@
+// error: hold blocks don't nest
+namespace;
+include rt;
+hold { shared let c; hold { shared let d; } }
+fn main() { return 0; }
diff --git a/tests/hold/reject/o3.zc b/tests/hold/reject/o3.zc
new file mode 100644
index 0000000..87c2dd5
--- /dev/null
+++ b/tests/hold/reject/o3.zc
@@ -0,0 +1,5 @@
+// error: f: is in a hold block and can't be o3
+namespace;
+include rt;
+hold { shared let c; o3 int f(int k) { return k; } }
+fn main() { return f(1); }
diff --git a/tests/hold/reject/order.zc b/tests/hold/reject/order.zc
new file mode 100644
index 0000000..9a2943b
--- /dev/null
+++ b/tests/hold/reject/order.zc
@@ -0,0 +1,7 @@
+// trap: was entered while
+// blocks are entered in declaration order; going back to an earlier block while a later one is held stops the program
+namespace;
+include rt;
+hold { shared let a; fn ga() { a++; return a; } }
+hold { shared let b; fn gb() { b++; return ga(); } }
+fn main() { rt.put_n(gb()); rt.put_c(10); return 0; }
diff --git a/tests/hold/reject/outside.zc b/tests/hold/reject/outside.zc
new file mode 100644
index 0000000..a202898
--- /dev/null
+++ b/tests/hold/reject/outside.zc
@@ -0,0 +1,5 @@
+// error: c: is shared in a hold block; only the functions written inside that block can use it
+namespace;
+include rt;
+hold { shared let c; fn a() { c++; return c; } }
+fn main() { c = 3; return a(); }
diff --git a/tests/hold/reject/pointer.zc b/tests/hold/reject/pointer.zc
new file mode 100644
index 0000000..6306a62
--- /dev/null
+++ b/tests/hold/reject/pointer.zc
@@ -0,0 +1,5 @@
+// error: name: is shared, so it holds numbers
+namespace;
+include rt;
+hold { shared char* name = "x"; fn a() { return 0; } }
+fn main() { return a(); }