<p dir="auto">In Julia Master (and 1.6)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; f(x) = (T=eltype(x); mapreduce(v-&gt;T(v), +, x))
julia&gt; @code_warntype f([3,4,5])
MethodInstance for f(::Vector{Int64})
  from f(x) in Main at REPL[2]:1
Arguments
  #self#::Core.Const(f)
  x::Vector{Int64}
Locals
  #3::var&quot;#3#4&quot;{DataType}
  T::Type{Int64}
Body::Any
1 ─      (T = Main.eltype(x))
│   %2 = Main.:(var&quot;#3#4&quot;)::Core.Const(var&quot;#3#4&quot;)
│   %3 = Core.typeof(T::Core.Const(Int64))::Core.Const(DataType)
│   %4 = Core.apply_type(%2, %3)::Core.Const(var&quot;#3#4&quot;{DataType})
│        (#3 = %new(%4, T::Core.Const(Int64)))
│   %6 = #3::Core.Const(var&quot;#3#4&quot;{DataType}(Int64))
│   %7 = Main.mapreduce(%6, Main.:+, x)::Any
└──      return %7"><pre class="notranslate"><code class="notranslate">julia&gt; f(x) = (T=eltype(x); mapreduce(v-&gt;T(v), +, x))
julia&gt; @code_warntype f([3,4,5])
MethodInstance for f(::Vector{Int64})
  from f(x) in Main at REPL[2]:1
Arguments
  #self#::Core.Const(f)
  x::Vector{Int64}
Locals
  #3::var"#3#4"{DataType}
  T::Type{Int64}
Body::Any
1 ─      (T = Main.eltype(x))
│   %2 = Main.:(var"#3#4")::Core.Const(var"#3#4")
│   %3 = Core.typeof(T::Core.Const(Int64))::Core.Const(DataType)
│   %4 = Core.apply_type(%2, %3)::Core.Const(var"#3#4"{DataType})
│        (#3 = %new(%4, T::Core.Const(Int64)))
│   %6 = #3::Core.Const(var"#3#4"{DataType}(Int64))
│   %7 = Main.mapreduce(%6, Main.:+, x)::Any
└──      return %7
</code></pre></div>
<p dir="auto">Could we make type inference smarter here?</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="function foo(a::AbstractVector)
    T = eltype(a)
    b = Vector{T}()
    c = [Set{T}() for x in a]
    return length(c)
end

a = rand(1:10, 200);"><pre class="notranslate"><code class="notranslate">function foo(a::AbstractVector)
    T = eltype(a)
    b = Vector{T}()
    c = [Set{T}() for x in a]
    return length(c)
end

a = rand(1:10, 200);
</code></pre></div>
<p dir="auto"><code class="notranslate">@code_warntype</code> shows an inference failure in <code class="notranslate">b</code> and <code class="notranslate">c</code>.</p>
<p dir="auto">Changing to <code class="notranslate">c = Set{T}[Set{T}() for x in a]</code> fixes <code class="notranslate">c</code>'s inference issue.</p>