mirror of
https://github.com/ziglang/zig.git
synced 2025-12-13 17:53:07 +00:00
These operations are allowed because the string literals are just pointers but they produce unexpected results. These errors prevent beginners from shooting themselves in the foot while still allowing advanced users to circumvent them if they desire to do so. Closes #8290
30 lines
528 B
Zig
30 lines
528 B
Zig
comptime {
|
|
var a = "foo";
|
|
if (a == "foo") unreachable;
|
|
}
|
|
comptime {
|
|
var a = "foo";
|
|
if (a == ("foo")) unreachable; // intentionally allow
|
|
}
|
|
comptime {
|
|
var a = "foo";
|
|
switch (a) {
|
|
"foo" => unreachable,
|
|
else => {},
|
|
}
|
|
}
|
|
comptime {
|
|
var a = "foo";
|
|
switch (a) {
|
|
("foo") => unreachable, // intentionally allow
|
|
else => {},
|
|
}
|
|
}
|
|
|
|
// error
|
|
// backend=stage2
|
|
// target=native
|
|
//
|
|
// :3:11: error: cannot compare strings with ==
|
|
// :12:9: error: cannot switch on strings
|