julia> fs() = rand(Bool) ? (1,1) : (1.0, 1.0)
fs (generic function with 1 method)
julia> f(fs, i) = fs()[i]
f (generic function with 1 method)
julia> g(fs) = (f(fs, 1), f(fs, 2))
g (generic function with 1 method)
julia> @code_warntype g(fs)
MethodInstance for g(::typeof(fs))
  from g(fs) @ Main REPL[3]:1
Arguments
  #self#::Core.Const(g)
  fs::Core.Const(fs)
Body::Tuple{Union{Float64, Int64}, Union{Float64, Int64}}
1 β %1 = Main.f(fs, 1)::Union{Float64, Int64}
β   %2 = Main.f(fs, 2)::Union{Float64, Int64}
β   %3 = Core.tuple(%1, %2)::Tuple{Union{Float64, Int64}, Union{Float64, Int64}}
βββ      return %3
Would it be possible to nudge the compiler to realize that the types of f(fs,1) must be the same as that of f(fs, 2), which would make the result a union of simple Tuples instead of a Tuple of unions? I canβt add type assertions to f and g.
 I was hoping that this may be handled at a lower level
 I was hoping that this may be handled at a lower level