From 2df386271892d7e64334401302a5fb8a8712cbfd Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 21:25:06 +0330 Subject: conformance: defer block form without a trailing semicolon, several statements and a local, at a return and at the end of the scope --- tests/conformance/4-statements/defer_block.zc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/conformance/4-statements/defer_block.zc 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 -- cgit v1.2.3