Skip to content

Commit ff39b09

Browse files
committed
partial fix for #38
1 parent 7ab2efd commit ff39b09

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/functor.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ functor(T, x) = (), _ -> x
33
functor(x) = functor(typeof(x), x)
44

55
functor(::Type{<:Tuple}, x) = x, y -> y
6-
functor(::Type{<:NamedTuple}, x) = x, y -> y
6+
functor(::Type{<:NamedTuple{L}}, x) where L = NamedTuple{L}(map(s -> getproperty(x, s), L)), identity
77

88
functor(::Type{<:AbstractArray}, x) = x, y -> y
99
functor(::Type{<:AbstractArray{<:Number}}, x) = (), _ -> x

test/basics.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ end
115115

116116
# Reconstruction type comes from the first argument
117117
foo1 = Foo([7,8], 9)
118-
@test_broken fmap(+, m1, foo1) == (x = [8, 10], y = 12) # https://github.com/FluxML/Functors.jl/issues/38
118+
@test fmap(+, m1, foo1) == (x = [8, 10], y = 12)
119119
@test fmap(+, foo1, n1) isa Foo
120120
@test fmap(+, foo1, n1).x == [11, 13]
121121

122122
# Mismatched trees should be an error
123123
m2 = (x = [1,2], y = (a = [3,4], b = 5))
124124
n2 = (x = [6,7], y = 8)
125-
@test_throws ArgumentError fmap(firsttuple, m2, n2)
126-
@test_broken @test_throws ArgumentError fmap(firsttuple, m2, n2) # now (x = [6, 7], y = 8)
125+
@test_throws Exception fmap(firsttuple, m2, n2)
126+
@test_throws Exception fmap(firsttuple, m2, n2)
127127

128128
# The cache uses IDs from the first argument
129129
shared = [1,2,3]

0 commit comments

Comments
 (0)