Skip to content

Commit

Permalink
Fix unwrap_rec for singleton types
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Nov 14, 2019
1 parent 10cc459 commit fd02484
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ChainCutters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ Base.setindex(x::Const, I...) = _cut(Base.setindex(unwrap(x), I...))
Base.setindex(x::Variable, I...) = _uncut(Base.setindex(unwrap(x), I...))

@inline unwrap_rec(x::T) where T =
if Base.isstructtype(T)
if Base.issingletontype(T)
x
elseif Base.isstructtype(T)
constructorof(T)(unwrap_rec(fieldvalues(x))...)
else
x
Expand Down
1 change: 1 addition & 0 deletions test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ using Setfield
using Test

@test unwrap_rec(@lens _.a[$1]) === @lens _.a[$1]
@test unwrap_rec(Val(1)) === Val(1)

end # module

0 comments on commit fd02484

Please sign in to comment.