JuliaCollections/FunctionalCollections.jl

Building PersistentHashMap through in-line for loop has different behavior than Dict

Opened this issue · 0 comments

mopg commented

The code below throws an error BoundsError: attempt to access 1-element Array{Float64,1} at index [2], which seems to be a bug. When in the same code PersistentHashMap is replaced with Dict, the code works as expected.

function update()
    
    idx = 1

    a = Dict(:a=>0.)

    vec = [2.]

    results_cases = PersistentHashMap(
        case_key => 
            begin
                @info " " idx
                idx += 1
                vec[idx-1]
            end
         for (case_key,case) in a
    )

    return results_cases

end

update()

(I realize this code in and of itself does not make sense, however, it's part of a bigger piece of code where this kind of code is needed. Regardless this seems like a bug that should be fixed)