mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
parent
6e7ae66871
commit
8470b6ea37
@ -1864,15 +1864,16 @@ pub const SrcLoc = struct {
|
|||||||
if (want_case_idx.isSpecial()) {
|
if (want_case_idx.isSpecial()) {
|
||||||
break case;
|
break case;
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const is_multi = case.ast.values.len != 1 or
|
const is_multi = case.ast.values.len != 1 or
|
||||||
node_tags[case.ast.values[0]] == .switch_range;
|
node_tags[case.ast.values[0]] == .switch_range;
|
||||||
|
|
||||||
if (!want_case_idx.isSpecial()) switch (want_case_idx.kind) {
|
switch (want_case_idx.kind) {
|
||||||
.scalar => if (!is_multi and want_case_idx.index == scalar_i) break case,
|
.scalar => if (!is_multi and want_case_idx.index == scalar_i) break case,
|
||||||
.multi => if (is_multi and want_case_idx.index == multi_i) break case,
|
.multi => if (is_multi and want_case_idx.index == multi_i) break case,
|
||||||
};
|
}
|
||||||
|
|
||||||
if (is_multi) {
|
if (is_multi) {
|
||||||
multi_i += 1;
|
multi_i += 1;
|
||||||
|
|||||||
46
test/cases/compile_errors/invalid_switch_item.zig
Normal file
46
test/cases/compile_errors/invalid_switch_item.zig
Normal file
@ -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
|
||||||
Loading…
x
Reference in New Issue
Block a user