JLD.jl
JLD.jl copied to clipboard
Using JLD in a module, when it's not loaded in Main, causes issues
trafficstars
When trying write a storage module that would internally use JLD, I ran into the following weird behavior:
julia> using JLD
julia> save("d.jld", "d", Dict("a" => 1.0))
then restart Julia to clear the workspace so that JLD is no longer loaded and go
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.1.0 (2019-01-21)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> module Mod
using JLD
@show typeof(load("d.jld", "d"))
end
┌ Warning: type JLD.AssociativeWrapper{Core.String,Core.Float64,Base.Dict{Core.String,Core.Float64}} not present in workspace; reconstructing
└ @ JLD ~/.julia/packages/JLD/1BoSz/src/jld_types.jl:703
typeof(load("d.jld", "d")) = getfield(JLD, Symbol("##JLD.AssociativeWrapper{Core.String,Core.Float64,Base.Dict{Core.String,Core.Float64}}#363"))
Main.Mod
This can be fixed by just loading JLD in Main:
julia> using JLD
julia> module Mod
using JLD
@show typeof(load("d.jld", "d"))
end
WARNING: replacing module Mod.
typeof(load("d.jld", "d")) = Dict{String,Float64}
Main.Mod
This seems related to https://github.com/JuliaIO/JLD.jl/issues/216, but I lack the understanding to judge whether it's actually a duplicate.
Hello, Did you find a workaround? Regards
It's been 3 years, I can't recall at all, sorry.