JuliaIO / JLD2.jl

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

Saving/Reloading a struct with more than 255 fields leads to a "missing field" warning & corrupted loads #558

Closed ChristianBayerEcon closed 1 month ago

ChristianBayerEcon commented 1 month ago

A minimum working example is the following:

using JLD2

# Define a struct with 256 fields
count=256
fields = [Symbol("field",i) for i in 1:count]
@eval struct MyStruct
    $(fields...)
end

# Fill the struct
myStructInstance = MyStruct(ntuple(i -> i, count)...)

# Save the struct
@save "myStruct.jld2" myStructInstance

# Load the struct
@load "myStruct.jld2" myStructInstance

if count is 255 this works as expected but with 256 the following error occurs

┌ Warning: saved type MyStruct is missing field field1 in workspace type; reconstructing
└ @ JLD2 ~/.julia/packages/JLD2/VWinU/src/data/reconstructing_datatypes.jl:207

The resulting load is an empty struct

julia> myStructInstance
Reconstruct@MyStruct(())

Julia is 1.10 and JLD2 is the most recent version.

Is this a known bug? Or do I need to change any parameters of the @save command? (using jldsave/jldopen results in the same behavior)

JonasIsensee commented 1 month ago

Fascinating. That wasn't a known bug so faf. I'll try to fix it in the next few days.