zig
zig copied to clipboard
"Array where slice is expected" error always says "array literal" even when not using a literal.
Zig Version
0.12.0
Steps to Reproduce and Observed Output
testing the following x.zig file:
fn takesSlice(slice: []const u8) void {
_ = slice;
}
test {
const array: [0]u8 = undefined; // length doesn't matter here
takesSlice(array);
}
Produces this compile error:
x.zig:10:16: error: array literal requires address-of operator (&) to coerce to slice type '[]const u8'
takesSlice(array);
^~~~~
Expected Output
I would expect the error message to only mention array literals when the offending code uses an array literal (i.e. [_]T{ ... } syntax). Otherwise I would expect the error message to just say "array requires address-of operator ..." and omit the "literal" part from the message.