zig/test/cases/compile_errors/invalid_switch_item.zig
2025-01-22 04:11:02 +00:00

47 lines
870 B
Zig

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