JuliaIO / JLD.jl

Saving and loading julia variables while preserving native types
MIT License
278 stars 55 forks source link

Parametric type load errors with StaticArrays: ERROR: stored type does not match currently loaded type #294

Closed BoZenKhaa closed 3 years ago

BoZenKhaa commented 3 years ago

Hello, I am having issues loading saved custom parametric type using StaticArrays in Julia 1.5.

The following example:

using JLD
using StaticArrays

struct MyType{N}
    a::SVector{N, Int64}
end

MyType{2}(SA[1,2])

JLD.save("test.jld", "s", MyType{2}(SA[1,2]))
load("test.jld")

produces this error:

ERROR: stored type MyType{2} does not match currently loaded type

I get the same error if the parameter is the type and not the size.

Everything works fine when using the StaticArray directly:

julia> JLD.save("test.jld", "s", SVector{2, Int64}(1,2))

julia> load("test.jld")
Dict{String,Any} with 1 entry:
  "s" => [1, 2]

Similarly, using custom nested parametric types works fine as well:

struct MyType3{T}
    a::T
end

struct MyType4{T}
    b::MyType3{T}
end

MyType4{Int64}(MyType3{Int64}(1))

JLD.save("test.jld", "s", MyType4{Int64}(MyType3{Int64}(1)))

julia> load("test.jld")
Dict{String,Any} with 1 entry:
  "s" => MyType4{Int64}(MyType3{Int64}(1))

What could be causing this? I get this error only with my own parametric types using StaticArrays. I have posted this also in StaticArrays: https://github.com/JuliaArrays/StaticArrays.jl/issues/877