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
Filled array with array iterates "wrongly". #91501
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Arrays are passed by reference, you fill the outer array with a reference to the same array. This is already documented:
We could solve this by adding optional parameters |
and
changing to a.fill([].duplicate(false)) still produces the same output, even on 4.3dev5 |
This shouldn't change anything. You create the array once, make a duplicate once, and pass the duplicate to In other words, the expression |
(note the outdated hidden comment, I got this confused with another bug related to shared literals) |
So, the patterns are NOT and SHOULD NOT be equivalent? Ok, so there is NO WAY to fill a array with a blank arrays using fill() and one need to use the iterator to alocate/or push the blank non referenced arrays inside it, and this is the only way to do that? If so, ok, no more to discuss, but i, nonetheless, find it odd. Will just stick to iterate it fully and forget about the fill, and maybe even the resize, on that use case. Thanks. |
Yes, they shouldn't.
I think this should be opened as a proposal instead, if you're interested. However, the current behavior appears to be correct as is: Given the above, let's close this issue, since the behavior is not a bug and is correctly documented. Thanks for the contribution nonetheless! |
Tested versions
3.5.3
System information
editor
Issue description
When running:
you get:
[[3161026589, 2668139190, 4134715227], [3161026589, 2668139190, 4134715227], [3161026589, 2668139190, 4134715227]]
[[4204663500], [1099556929], [3154986942]]
It seens that both outputs must be like the second one.
The first case is iterating again inside the branches, and copying the values.
Or i am missing something? i tried using fill([].duplicate()) but same behaviour.
Steps to reproduce
run the code
Minimal reproduction project (MRP)
Bug Array.zip
The text was updated successfully, but these errors were encountered: