aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 21:25:06 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 21:25:06 +0330
commit2df386271892d7e64334401302a5fb8a8712cbfd (patch)
tree633ebf61f6befc32bdc2d8492bfefb701e41f781
parentdefer: any single statement (if/else, loops, switch, unchecked, unbounded), n... (diff)
conformance: defer block form without a trailing semicolon, several statements and a local, at a return and at the end of the scope
-rw-r--r--tests/conformance/4-statements/defer_block.zc23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/conformance/4-statements/defer_block.zc b/tests/conformance/4-statements/defer_block.zc
new file mode 100644
index 0000000..4424688
--- /dev/null
+++ b/tests/conformance/4-statements/defer_block.zc
@@ -0,0 +1,23 @@
+// expect: 1 2 30 31 9 /1 2 4 30 31 /5 3 /
+// spec 4.14.1: the block form `defer { ... }`, with no semicolon after it: several statements and a local of its own, run at every exit of the scope
+include rt;
+void pn(int x) { rt.put_n(x); rt.put_c(32); }
+int f(int c) {
+ defer {
+ int k = 30;
+ pn(k);
+ pn(k + 1);
+ }
+ pn(1);
+ pn(2);
+ if (c) { pn(4); return 0; }
+ return 9;
+}
+fn main() {
+ pn(f(0)); rt.put_c(10);
+ f(1); rt.put_c(10);
+ { defer { pn(3); } pn(5); }
+ rt.put_c(10);
+ return 0;
+}
+// zc0: skip