Skip to content

Commit

Permalink
Merge pull request #72 from oschulz/anymutable-fix
Browse files Browse the repository at this point in the history
Fix anymutable errors with self-referencing types
  • Loading branch information
ToucheSir authored Feb 7, 2024
2 parents 19788ea + a7d2b8e commit 942126f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name = "Functors"
uuid = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
authors = ["Mike J Innes <[email protected]>"]
version = "0.4.6"
version = "0.4.7"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[compat]
Documenter = "0.27"
Documenter = "1"
julia = "1.6"

[extras]
Expand Down
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

[compat]
Documenter = "1"
1 change: 0 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ makedocs(modules = [Functors],
sitename = "Functors.jl",
pages = ["Home" => "index.md",
"API" => "api.md"],
strict = [:cross_references, :missing_docs],
format = Documenter.HTML(
analytics = "UA-36890222-9",
assets = ["assets/flux.css"],
Expand Down
2 changes: 1 addition & 1 deletion src/Functors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ To recurse into custom types without reconstructing them afterwards,
use [`fmapstructure`](@ref).
For advanced customization of the traversal behaviour,
pass a custom `walk` function that subtypes [`Functors.AbstractWalk`](ref).
pass a custom `walk` function that subtypes [`Functors.AbstractWalk`](@ref).
The call `fmap(f, x, ys...; walk = mywalk)` will wrap `mywalk` in
[`ExcludeWalk`](@ref) then [`CachedWalk`](@ref).
Here, [`ExcludeWalk`](@ref) is responsible for applying `f` at excluded nodes.
Expand Down
3 changes: 2 additions & 1 deletion src/walks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ usecache(::Nothing, x) = false

@generated function anymutable(x::T) where {T}
ismutabletype(T) && return true
subs = [:(anymutable(getfield(x, $f))) for f in QuoteNode.(fieldnames(T))]
fns = QuoteNode.(filter(n -> fieldtype(T, n) != T, fieldnames(T)))
subs = [:(anymutable(getfield(x, $f))) for f in fns]
return Expr(:(||), subs...)
end

Expand Down
4 changes: 4 additions & 0 deletions test/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ end
end
end

@testset "Self-referencing types" begin
@test fmap(identity, Base.ImmutableDict(:a => 42)) == Base.ImmutableDict(:a => 42)
end

@testset "functor(typeof(x), y) from @functor" begin
nt1, re1 = functor(Foo, (x=1, y=2, z=3))
@test nt1 == (x = 1, y = 2)
Expand Down

4 comments on commit 942126f

@ToucheSir
Copy link
Member Author

Choose a reason for hiding this comment

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

@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/100422

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.4.7 -m "<description of version>" 942126fe09689b2f8a94a7ace33bb714bddb232e
git push origin v0.4.7

Also, note the warning: Version 0.4.7 skips over 0.4.6
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

@ToucheSir
Copy link
Member Author

Choose a reason for hiding this comment

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

@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 updated: JuliaRegistries/General/100422

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.4.7 -m "<description of version>" 942126fe09689b2f8a94a7ace33bb714bddb232e
git push origin v0.4.7

Please sign in to comment.