aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors/invalid_compare_string.zig
blob: 7a2bebf6b0a75d71ca729130cb99f27c058a0f0b (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
comptime {
    const a = "foo";
    if (a != "foo") unreachable;
}
comptime {
    const a = "foo";
    if (a == "foo") {} else unreachable;
}
comptime {
    const a = "foo";
    if (a != ("foo")) {} // intentionally allow
    if (a == ("foo")) {} // intentionally allow
}
comptime {
    const a = "foo";
    switch (a) {
        "foo" => {},
        else => unreachable,
    }
}
comptime {
    const a = "foo";
    switch (a) {
        ("foo") => {}, // intentionally allow
        else => {},
    }
}

// error
// backend=stage2
// target=native
//
// :3:11: error: cannot compare strings with !=
// :7:11: error: cannot compare strings with ==
// :17:9: error: cannot switch on strings