diff --git a/CHANGELOG.md b/CHANGELOG.md index a9cf5270..f2a4f04e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.5.3 + - Bugfix for `<: Function` structs + ## 0.5.2 - Remove left-over warning - Restrict warning for storing `Function` objects to `anonymous` functions. diff --git a/Project.toml b/Project.toml index 838735c1..9361c70c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "JLD2" uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819" -version = "0.5.2" +version = "0.5.3" [deps] FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" diff --git a/src/data/writing_datatypes.jl b/src/data/writing_datatypes.jl index cc414c17..3619a289 100644 --- a/src/data/writing_datatypes.jl +++ b/src/data/writing_datatypes.jl @@ -445,7 +445,7 @@ end function h5convert!(out::Pointers, ::DataTypeODR, f::JLDFile, T::DataType, wsession::JLDWriteSession) t = typename(T) - if T <: Function && isgensym(nameof(T.instance)) + if T <: Function && isgensym(Symbol(T)) @warn LazyString("Attempting to store ", T, ".\n", "JLD2 only stores functions by name.\n", " This may not be useful for anonymous functions.") diff --git a/test/loadsave.jl b/test/loadsave.jl index e4e0a434..30329062 100644 --- a/test/loadsave.jl +++ b/test/loadsave.jl @@ -788,4 +788,16 @@ if VERSION ≥ v"1.7" f = x -> x+1 @test_warn contains("Attempting to store") save_object(fn, f) end -end \ No newline at end of file +end + +struct Foo601 <: Function + x::Int +end + +@testset "Issue #601: Storing <: Function objects" begin + foo = Foo601(2) + tempfile = tempname() + jldsave(tempfile; foo) + loaded_foo = load(tempfile, "foo") + @test loaded_foo isa Foo601 +end