JuliaIO / JLD2.jl

HDF5-compatible file format in pure Julia
Other
534 stars 82 forks source link

Error loading file saved with v0.4.41 on v0.4.43 #532

Closed jishnub closed 5 months ago

jishnub commented 5 months ago

The following works on v0.4.41 using Julia v1.10.0:

julia> f() = (1, pairs((;)))
f (generic function with 3 methods)

julia> jldsave("testopempty.jld2", op=f())

julia> load("testopempty.jld2")
Dict{String, Any} with 1 entry:
  "op" => (1, Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}())

However, using v0.4.43, I obtain

julia> load("testopempty.jld2")
Error encountered while load FileIO.File{FileIO.DataFormat{:JLD2}, String}("testopempty.jld2").

Fatal error:
ERROR: Tuple field type cannot be Union{}
Stacktrace:
  [1] fileio_load(f::FileIO.File{FileIO.DataFormat{:JLD2}, String}; nested::Bool, kwargs::@Kwargs{})
    @ JLD2 ~/.julia/packages/JLD2/S2STH/src/fileio.jl:46
  [2] fileio_load(f::FileIO.File{FileIO.DataFormat{:JLD2}, String})
    @ JLD2 ~/.julia/packages/JLD2/S2STH/src/fileio.jl:37
  [3] #invokelatest#2
    @ ./essentials.jl:887 [inlined]
  [4] invokelatest
    @ ./essentials.jl:884 [inlined]
  [5] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::@Kwargs{})
    @ FileIO ~/.julia/packages/FileIO/jMf68/src/loadsave.jl:219
  [6] action
    @ ~/.julia/packages/FileIO/jMf68/src/loadsave.jl:196 [inlined]
  [7] action
    @ ~/.julia/packages/FileIO/jMf68/src/loadsave.jl:185 [inlined]
  [8] load(::String; options::@Kwargs{})
    @ FileIO ~/.julia/packages/FileIO/jMf68/src/loadsave.jl:113
  [9] load(::String)
    @ FileIO ~/.julia/packages/FileIO/jMf68/src/loadsave.jl:109
 [10] top-level scope
    @ REPL[2]:1
Stacktrace:
 [1] handle_error(e::ErrorException, q::Base.PkgId, bt::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}})
   @ FileIO ~/.julia/packages/FileIO/jMf68/src/error_handling.jl:61
 [2] handle_exceptions(exceptions::Vector{Tuple{Any, Union{Base.PkgId, Module}, Vector}}, action::String)
   @ FileIO ~/.julia/packages/FileIO/jMf68/src/error_handling.jl:56
 [3] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::@Kwargs{})
   @ FileIO ~/.julia/packages/FileIO/jMf68/src/loadsave.jl:228
 [4] action
   @ ~/.julia/packages/FileIO/jMf68/src/loadsave.jl:196 [inlined]
 [5] action
   @ ~/.julia/packages/FileIO/jMf68/src/loadsave.jl:185 [inlined]
 [6] load(::String; options::@Kwargs{})
   @ FileIO ~/.julia/packages/FileIO/jMf68/src/loadsave.jl:113
 [7] load(::String)
   @ FileIO ~/.julia/packages/FileIO/jMf68/src/loadsave.jl:109
 [8] top-level scope
   @ REPL[2]:1

This seems to hit https://github.com/JuliaLang/julia/issues/52385

JonasIsensee commented 5 months ago

Hi @jishnub, thanks for this concise report. I added two method definitions to achieve the correct dispatch and fix this case in #534