Skip to content

Commit 4f9c4ea

Browse files
authored
Merge pull request #389 from JuliaDiff/ox/tanprint
Fix printing of Tangent{T} with empty backing
2 parents 653cd7d + 2a9e32b commit 4f9c4ea

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/differentials/composite.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ function Base.show(io::IO, comp::Tangent{P}) where P
6060
print(io, "Tangent{")
6161
show(io, P)
6262
print(io, "}")
63-
# allow Tuple or NamedTuple `show` to do the rendering of brackets etc
64-
show(io, backing(comp))
63+
if isempty(backing(comp))
64+
print(io, "()") # so it doesn't show `NamedTuple()`
65+
else
66+
# allow Tuple or NamedTuple `show` to do the rendering of brackets etc
67+
show(io, backing(comp))
68+
end
6569
end
6670

6771
Base.convert(::Type{<:NamedTuple}, comp::Tangent{<:Any, <:NamedTuple}) = backing(comp)

test/differentials/composite.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ end
325325
r"^Tangent{Tuple{Int64,\s?Int64}}\(1,\s?2\)$",
326326
repr(Tangent{Tuple{Int64,Int64}}(1, 2)),
327327
)
328+
329+
@test repr(Tangent{Foo}()) == "Tangent{Foo}()"
328330
end
329331

330332
@testset "internals" begin

0 commit comments

Comments
 (0)