-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
acceptedThis proposal is planned.This proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
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};
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.