Skip to content
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

[WONTFIX] fill() is a footgun #55158

Closed
LebedevRI opened this issue Jul 17, 2024 · 2 comments
Closed

[WONTFIX] fill() is a footgun #55158

LebedevRI opened this issue Jul 17, 2024 · 2 comments
Labels
duplicate Indicates similar issues or pull requests

Comments

@LebedevRI
Copy link
Contributor

I've spent last 3+ days trying to understand why my code, wasn't doing what i expected it to do,
Reduced from a much larger code (a JuMP model):

import Combinatorics

function foo()
    v1 = [1 => 3, 1 => 4, 2 => 3, 2 => 4]
    v2 = [Pair{String, String}[], [2 => 4, 1 => 3], Pair{String, String}[]]

    v3 = 10
    v4 = length(v2)
    
    v5 = fill(fill(false, (v3, v3)), v4)
    for k in 1:v4
        for connection in v1
            r = (connection in v2[k])
            for cidx in Combinatorics.permutations(connection)
                (v5[k])[cidx...] = r
            end
        end
        if k>=2
            @show(v5[2])
        end
    end
end

foo()

After a while, i've finally noticed that this would output:

v5[2] = Bool[0 0 1 0 0 0 0 0 0 0; 0 0 0 1 0 0 0 0 0 0; 1 0 0 0 0 0 0 0 0 0; 0 1 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0]
v5[2] = Bool[0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0]

... which is, while is a documented behavior, is really surprising :/

@mbauman
Copy link
Sponsor Member

mbauman commented Jul 17, 2024

Duplicate of #41209

@mbauman mbauman marked this as a duplicate of #41209 Jul 17, 2024
@mbauman mbauman closed this as not planned Won't fix, can't repro, duplicate, stale Jul 17, 2024
@mbauman mbauman added the duplicate Indicates similar issues or pull requests label Jul 17, 2024
@LebedevRI
Copy link
Contributor Author

@mbauman thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Indicates similar issues or pull requests
Projects
None yet
Development

No branches or pull requests

2 participants