aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors/invalid_switch_item.zig
blob: ee8c2a8b36e6d79e47a9e072234cb987202a1534 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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