Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix anymutable errors with self-referencing types #72

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <mike.j.innes@gmail.com>"]
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
Loading