aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors
diff options
context:
space:
mode:
authorMatthew Lugg <mlugg@mlugg.co.uk>2025-01-22 16:47:45 +0000
committerGitHub <noreply@github.com>2025-01-22 16:47:45 +0000
commit61fe307d0f05eea901577900f4ab2bdaf0ffb35f (patch)
tree540a47aad6da00421777f121c6b9e568f541918f /test/cases/compile_errors
parent941677e08318c2baaabc9d0fc87892d1b63487ae (diff)
parente864c38cc38095a1496229803465fdd0d079f9c3 (diff)
downloadzig-61fe307d0f05eea901577900f4ab2bdaf0ffb35f.tar.gz
zig-61fe307d0f05eea901577900f4ab2bdaf0ffb35f.zip
Merge pull request #22571 from mlugg/various-fixes-again
compiler: a few fixes
Diffstat (limited to 'test/cases/compile_errors')
-rw-r--r--test/cases/compile_errors/invalid_switch_item.zig46
-rw-r--r--test/cases/compile_errors/runtime_condition_in_inline_loop.zig16
2 files changed, 62 insertions, 0 deletions
diff --git a/test/cases/compile_errors/invalid_switch_item.zig b/test/cases/compile_errors/invalid_switch_item.zig
new file mode 100644
index 0000000000..ee8c2a8b36
--- /dev/null
+++ b/test/cases/compile_errors/invalid_switch_item.zig
@@ -0,0 +1,46 @@
+const E = enum { a, b, c };
+var my_e: E = .a;
+
+export fn f0() void {
+ switch (my_e) {
+ .a => {},
+ .b => {},
+ .x => {},
+ .c => {},
+ }
+}
+
+export fn f1() void {
+ switch (my_e) {
+ else => {},
+ .x, .y => {},
+ }
+}
+
+export fn f2() void {
+ switch (my_e) {
+ else => {},
+ .a => {},
+ .x, .y => {},
+ .b => {},
+ }
+}
+
+export fn f3() void {
+ switch (my_e) {
+ .a, .b => {},
+ .x, .y => {},
+ else => {},
+ }
+}
+
+// error
+//
+// :8:10: error: no field named 'x' in enum 'tmp.E'
+// :1:11: note: enum declared here
+// :16:10: error: no field named 'x' in enum 'tmp.E'
+// :1:11: note: enum declared here
+// :24:10: error: no field named 'x' in enum 'tmp.E'
+// :1:11: note: enum declared here
+// :32:10: error: no field named 'x' in enum 'tmp.E'
+// :1:11: note: enum declared here
diff --git a/test/cases/compile_errors/runtime_condition_in_inline_loop.zig b/test/cases/compile_errors/runtime_condition_in_inline_loop.zig
new file mode 100644
index 0000000000..65ed3d0367
--- /dev/null
+++ b/test/cases/compile_errors/runtime_condition_in_inline_loop.zig
@@ -0,0 +1,16 @@
+var rt_slice: []const u8 = &.{ 1, 2, 3 };
+
+export fn foo() void {
+ inline for (rt_slice) |_| {}
+}
+
+export fn bar() void {
+ inline while (rt_slice.len == 0) {}
+}
+
+// error
+//
+// :4:17: error: unable to resolve comptime value
+// :4:17: note: inline loop condition must be comptime-known
+// :8:32: error: unable to resolve comptime value
+// :8:32: note: inline loop condition must be comptime-known