aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors
diff options
context:
space:
mode:
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