Skip to content

Using JLD in a module, when it's not loaded in Main, causes issues #252

@mhauru

Description

@mhauru

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 #216, but I lack the understanding to judge whether it's actually a duplicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions