aboutsummaryrefslogtreecommitdiff
path: root/tests/conformance/4-statements
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 22:28:06 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 22:28:06 +0330
commit5a4dc62a79af6135c7050e81a82dbfdfb0a7d4e0 (patch)
tree805283b2d30b2cf0f53af42e5a3fc119af5e839f /tests/conformance/4-statements
parentdefinite assignment: reading a local before it is initialized is a compile er... (diff)
uninit: track aggregate fills per part, sticky computed-index fills, &a[k] and method calls set the aggregate; fix test/example hits; docs
Diffstat (limited to 'tests/conformance/4-statements')
-rw-r--r--tests/conformance/4-statements/uninit_array_elems_ok.zc11
-rw-r--r--tests/conformance/4-statements/uninit_array_fill_loop_ok.zc9
-rw-r--r--tests/conformance/4-statements/uninit_struct_fields_ok.zc13
3 files changed, 33 insertions, 0 deletions
diff --git a/tests/conformance/4-statements/uninit_array_elems_ok.zc b/tests/conformance/4-statements/uninit_array_elems_ok.zc
new file mode 100644
index 0000000..00f4d17
--- /dev/null
+++ b/tests/conformance/4-statements/uninit_array_elems_ok.zc
@@ -0,0 +1,11 @@
+// expect: 6
+// spec 4.1.5: writing every element by constant index sets the array
+include rt;
+fn main() {
+ int[3] a;
+ a[0] = 1; a[1] = 2; a[2] = 3;
+ int s = 0;
+ for (int i = 0; i < 3; i++) s = s + a[i];
+ rt.put_n(s);
+ return 0;
+}
diff --git a/tests/conformance/4-statements/uninit_array_fill_loop_ok.zc b/tests/conformance/4-statements/uninit_array_fill_loop_ok.zc
new file mode 100644
index 0000000..3b017b9
--- /dev/null
+++ b/tests/conformance/4-statements/uninit_array_fill_loop_ok.zc
@@ -0,0 +1,9 @@
+// expect: 30
+// spec 4.1.5: a computed-index fill counts as setting the whole array
+include rt;
+fn main() {
+ int[4] a;
+ for (int i = 0; i < 4; i++) a[i] = i * 5;
+ rt.put_n(a[0] + a[1] + a[2] + a[3]);
+ return 0;
+}
diff --git a/tests/conformance/4-statements/uninit_struct_fields_ok.zc b/tests/conformance/4-statements/uninit_struct_fields_ok.zc
new file mode 100644
index 0000000..a12fa71
--- /dev/null
+++ b/tests/conformance/4-statements/uninit_struct_fields_ok.zc
@@ -0,0 +1,13 @@
+// expect: 3/7/
+// spec 4.1.5: a written field may be read before the rest; writing every field sets the struct
+include rt;
+struct point { int x; int y; }
+fn sum(point* q) { return q.x + q.y; }
+fn main() {
+ point p;
+ p.x = 3;
+ rt.put_n(p.x); rt.put_c(10);
+ p.y = 4;
+ rt.put_n(sum(&p)); rt.put_c(10);
+ return 0;
+}