zig
zig copied to clipboard
Unhelpful Error Message: Else-If Typo
Zig Version
0.10.0-dev.4418+99c3578f6
Steps to Reproduce
Write Zig code which uses an else if statement, but misses out the if keyword, for example:
const std = @import("std");
pub fn main() void {
const foo = 20;
if (foo == 30) {
std.log.info("30", .{});
} else (foo > 30) {
std.log.info(">30", .{});
} else {
std.log.info("<30", .{});
}
}
Expected Behavior
Zig should output a useful compile error, pointing the programmer to the problem, such as:
tmp.zig:7:12: error: expected 'if' before condition
} else (foo > 30) {
^~~~~~~~~~
Actual Behavior
Zig outputs a near-useless compile error, diverting attention away from the typo:
tmp.zig:8:33: error: expected ',' after initializer
std.log.info(">30", .{});
^