-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
checker: array.insert() does not work if the array contains fixed arrays #23090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The correct would be: fn main() {
mut arr := [][2]int{}
arr.insert(0, [[1, 2]!])
println(arr)
} |
no? this is |
I think LeoDeveloper is right. I think the problem could be related to the fixed array. For normal array elements below 7,8 are appended ok. fn main() {
mut arr := [][]int{}
arr << [1, 2]
arr << [[3, 4], [5, 6]]
arr.insert(arr.len, [7, 8]) // <- works as expected
arr.insert(arr.len, [[9,10]]) // <- not rejected but C error
println(arr)
} But I was expecting the compiler will reject elements 9 and 10, but not, generates a C error :-( |
The last one should have been a V error. You tried to insert an array of arrays as an array in the array. It would be the same as trying mut arr := []int{}
arr.insert(arr.len, [9,10]) In other words, the thing being inserted must have one fewer set of |
I think we should improve the error message. bug.v:3:16: error: cannot insert `[]int` to `[][2]int`
1 | fn main() {
2 | mut arr := [][2]int{}
3 | arr.insert(0, [1, 2])
| ~~~~~~
4 | println(arr)
5 | } |
I agree that the error message could be better, but remember the original code has arr.insert(0, [1, 2]!) which should work as it is trying to insert a fixed array, while your example has arr.insert(0, [1, 2]) which should not, since it isn't a fixed array. |
V doctor:
What did you do?
./v -g -o vdbg cmd/v && ./vdbg repro.v
What did you expect to see?
Successful compilation
What did you see instead?
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
Huly®: V_0.6-21528
The text was updated successfully, but these errors were encountered: