In the following example:
julia> @code_warntype (A -> ((λ,v) = eigen(A); (λ,v)))(rand(2,2))
MethodInstance for (::var"#19#20")(::Matrix{Float64})
from (::var"#19#20")(A) @ Main REPL[14]:1
Arguments
#self#::Core.Const(var"#19#20"())
A::Matrix{Float64}
Locals
@_3::Val{:vectors}
v::Union{Matrix{ComplexF64}, Matrix{Float64}}
λ::Union{Vector{ComplexF64}, Vector{Float64}}
Body::Tuple{Union{Vector{ComplexF64}, Vector{Float64}}, Union{Matrix{ComplexF64}, Matrix{Float64}}}
1 ─ %1 = Main.eigen(A)::Union{Eigen{ComplexF64, ComplexF64, Matrix{ComplexF64}, Vector{ComplexF64}}, Eigen{Float64, Float64, Matrix{Float64}, Vector{Float64}}}
│ %2 = Base.indexed_iterate(%1, 1)::Union{Tuple{Vector{ComplexF64}, Val{:vectors}}, Tuple{Vector{Float64}, Val{:vectors}}}
│ (λ = Core.getfield(%2, 1))
│ (@_3 = Core.getfield(%2, 2))
│ %5 = Base.indexed_iterate(%1, 2, @_3)::Union{Tuple{Matrix{ComplexF64}, Val{:done}}, Tuple{Matrix{Float64}, Val{:done}}}
│ (v = Core.getfield(%5, 1))
│ %7 = Core.tuple(λ, v)::Tuple{Union{Vector{ComplexF64}, Vector{Float64}}, Union{Matrix{ComplexF64}, Matrix{Float64}}}
└── return %7
The type of the result is inferred to be a Tuple
of Union
s, however, I know that this should ideally be a Union
of Tuple
s. Any suggestions on how to nudge the compiler to infer this as a simpler union, aside from adding type-assertions?