You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
1.18.6: broadcasting over an empty Vector{Union{}} throws UndefVarError: D once ReverseDiff is loaded #324
Versions: ReverseDiff 1.18.6 (1.18.5 is fine), Julia 1.12.5, Linux x86_64.
Reproducer (clean environment with only ReverseDiff):
using ReverseDiff
String.(Union{}[])
1.18.6:
ERROR: UndefVarError: `D` not defined in local scope
[1] getouttype @ ReverseDiff src/derivatives/broadcast.jl:103
...
[9] copy(::Broadcasted{ReverseDiff.TrackedStyle{1}, Tuple{Base.OneTo{Int64}}, Type{String}, Tuple{Vector{Union{}}}})
@ ReverseDiff src/derivatives/broadcast.jl:92
1.18.5 returns Union{}[].
Cause (as far as we can tell):Vector{Union{}} matches AbstractArray{<:TrackedReal} because Union{} <: TrackedReal. So the broadcast style resolves to TrackedStyle, and in copy the new line D = mapreduce(getouttype, promote_type, args) (broadcast.jl:92) calls getouttype(::AbstractArray{<:TrackedReal{<:Any, D}}) where {D} = D (line 102) with D unbound.
Impact: any package that broadcasts over an empty collection whose element type is Union{}
(for example an empty JSON array read by JSON3) fails once ReverseDiff is loaded anywhere in the
process, even though no tracked values are involved. We hit it through CCBlade → ImplicitAD → ReverseDiff.
Possible fixes: exclude Union{} element types from the TrackedStyle broadcast-style rule,
or guard getouttype (e.g. getouttype(::AbstractArray{Union{}}) = Union{}).
Activity
devmotion commentedon Oct 25, 2026
These undesired bottom types are so annoying. Here, we should be able to avoid it - but generally I'd really like something like JuliaLang/julia#62265
Don't claim arrays with a `Union{}` element type for `TrackedStyle` (#…