Skip to content

1.18.6: broadcasting over an empty Vector{Union{}} throws UndefVarError: D once ReverseDiff is loaded #324

Closed

Description

@mwhincup

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

  1. devmotion commented on Oct 25, 2026

    @devmotion
    Member

    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

  2. added a commit that references this issue on Oct 25, 2026
    51cda83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions