Skip to content

Commit

Permalink
Merge pull request #602 from SamuelBadr/master
Browse files Browse the repository at this point in the history
Fix error when trying to store instances of <: Function types
  • Loading branch information
JonasIsensee committed Sep 21, 2024
2 parents b54623f + b7c041a commit 32a49c0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/data/writing_datatypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
14 changes: 13 additions & 1 deletion test/loadsave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

2 comments on commit 32a49c0

@JonasIsensee
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Notes:

  • Bugfix for <: Function structs

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/115632

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.3 -m "<description of version>" 32a49c0b0e028d776f2c27eec163f219dbce88d1
git push origin v0.5.3

Please sign in to comment.