Skip to content

Commit 9c8c812

Browse files
authored
handling type-known empty containers in zero_tangent
1 parent 2387dc1 commit 9c8c812

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/tangent_types/abstract_zero.jl

+6-1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ end
172172
function zero_tangent(::T) where {K,V,T<:AbstractDict{K,V}}
173173
return Tangent{T}(Dict{K,guess_zero_tangent_type(V)}())
174174
end
175+
zero_tangent(::Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}) = NoTangent()
176+
175177

176178
# Sad heauristic methods we need because of unassigned values
177179
guess_zero_tangent_type(::Type{T}) where {T<:Number} = T
@@ -180,6 +182,9 @@ function guess_zero_tangent_type(::Type{<:Array{T,N}}) where {T,N}
180182
return Array{guess_zero_tangent_type(T),N}
181183
end
182184
guess_zero_tangent_type(T::Type) = Any
185+
guess_zero_tangent_type(::Union{}) = Union{} # This will only show up for empty containers
186+
187+
183188

184189
# Stuff that conceptually has its own identity regardless of structual implementation and doesn't have a tangent
185190
zero_tangent(::Base.AbstractLogger) = NoTangent()
@@ -190,4 +195,4 @@ zero_tangent(::Expr) = NoTangent()
190195
zero_tangent(::Core.Compiler.AbstractInterpreter) = NoTangent()
191196
zero_tangent(::Core.Compiler.InstructionStream) = NoTangent()
192197
zero_tangent(::Core.CodeInfo) = NoTangent()
193-
zero_tangent(::Core.MethodInstance) = NoTangent()
198+
zero_tangent(::Core.MethodInstance) = NoTangent()

0 commit comments

Comments
 (0)