Allow spreading (dynamic) arrays without explicitly slicing them first #2266
SanderWassenberg
started this conversation in
Ideas/Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem/inconvenience
The spread operator only works on slices, and not arrays or dynamic arrays. This feels inconsistent.
I see
..
and[:]
as very similar operators, and as such I expect them both to work on the same data types. Instead if I want to spread an array I have to not only add..
as a prefix, but also still add[:]
as a suffix - just so that we're using the spread operator on a slice. To me it makes sense that the..
operator already performs the task of turning the (dynamic) array into a slice.Example
Solution
For consistency, the spread operator
..
should also work on fixed size arrays and dynamic arrays. The example above should then compile without issues.The error messages are also a tiny bit vague, it tells you that you're trying to assign the (dynamic) array to a slice, but doesn't say why (because of the spread operator...!). If my solution isn't implemented, it would at least be clearer if the message was something along the lines of "operator '..' only works on type slice, please use ..array[:]".
Beta Was this translation helpful? Give feedback.
All reactions