zig icon indicating copy to clipboard operation
zig copied to clipboard

"Array where slice is expected" error always says "array literal" even when not using a literal.

Open Trevor-Strong opened this issue 1 year ago • 0 comments

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.

Trevor-Strong avatar May 07 '24 14:05 Trevor-Strong