Closed
Description
Guess what @typeOf(mystery)
is:
var hi = "hi";
const mystery = [][]u8{&hi};
It's [1][]u8
. It looks like a double slice, but it's actually an array literal with an inferred number of items. It is equivalent to:
var hi = "hi";
const not_a_mystery = [1][]u8{&hi};
This is important because arrays usually can not be used where slices are expected, and it starts to get confusing with const
, especially when you consider that there is a missing compile error for this:
const why_isnt_this_an_error = []const []const{"hi"};
The const
on the array literal is nonsense and should be a compile error.
It's nice to infer the number of array items, but it shouldn't look like a slice. How about this syntax instead?
var hi = "hi";
const not_a_mystery = [_][]u8{&hi};