<p dir="auto">Consider the following example:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const PairUnion = Union{Pair{Int,Int8},Pair{Int,UInt8}}

array = PairUnion[1=&gt;0x2]

function pair1(a)
    x, y = a[1]
    x =&gt; y
end

function pair2(a)
    xy = a[1]
    x = xy.first
    y = xy.second
    x =&gt; y
end

function pair3(a)
    xy = a[1]
    x = first(xy)
    y = last(xy)
    x =&gt; y
end"><pre class="notranslate"><span class="pl-k">const</span> PairUnion <span class="pl-k">=</span> Union{Pair{Int,Int8},Pair{Int,UInt8}}

array <span class="pl-k">=</span> PairUnion[<span class="pl-c1">1</span><span class="pl-k">=&gt;</span><span class="pl-c1">0x2</span>]

<span class="pl-k">function</span> <span class="pl-en">pair1</span>(a)
    x, y <span class="pl-k">=</span> a[<span class="pl-c1">1</span>]
    x <span class="pl-k">=&gt;</span> y
<span class="pl-k">end</span>

<span class="pl-k">function</span> <span class="pl-en">pair2</span>(a)
    xy <span class="pl-k">=</span> a[<span class="pl-c1">1</span>]
    x <span class="pl-k">=</span> xy<span class="pl-k">.</span>first
    y <span class="pl-k">=</span> xy<span class="pl-k">.</span>second
    x <span class="pl-k">=&gt;</span> y
<span class="pl-k">end</span>

<span class="pl-k">function</span> <span class="pl-en">pair3</span>(a)
    xy <span class="pl-k">=</span> a[<span class="pl-c1">1</span>]
    x <span class="pl-k">=</span> <span class="pl-c1">first</span>(xy)
    y <span class="pl-k">=</span> <span class="pl-c1">last</span>(xy)
    x <span class="pl-k">=&gt;</span> y
<span class="pl-k">end</span></pre></div>
<p dir="auto">Then:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; @btime pair1($array)
  73.935 ns (1 allocation: 32 bytes)
1 =&gt; 0x02

julia&gt; @btime pair2($array)
  76.299 ns (1 allocation: 32 bytes)
1 =&gt; 0x02

julia&gt; @btime pair3($array)
  5.051 ns (0 allocations: 0 bytes)
1 =&gt; 0x02"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">pair1</span>(<span class="pl-k">$</span>array)
  <span class="pl-c1">73.935</span> ns (<span class="pl-c1">1</span> allocation<span class="pl-k">:</span> <span class="pl-c1">32</span> bytes)
<span class="pl-c1">1</span> <span class="pl-k">=&gt;</span> <span class="pl-c1">0x02</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">pair2</span>(<span class="pl-k">$</span>array)
  <span class="pl-c1">76.299</span> ns (<span class="pl-c1">1</span> allocation<span class="pl-k">:</span> <span class="pl-c1">32</span> bytes)
<span class="pl-c1">1</span> <span class="pl-k">=&gt;</span> <span class="pl-c1">0x02</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@btime</span> <span class="pl-c1">pair3</span>(<span class="pl-k">$</span>array)
  <span class="pl-c1">5.051</span> ns (<span class="pl-c1">0</span> allocations<span class="pl-k">:</span> <span class="pl-c1">0</span> bytes)
<span class="pl-c1">1</span> <span class="pl-k">=&gt;</span> <span class="pl-c1">0x02</span></pre></div>
<p dir="auto">When looking at <code class="notranslate">@code_warntype</code>, it looks like <code class="notranslate">x</code> and <code class="notranslate">y</code> are inferred to be <code class="notranslate">Union{Int,Int8,UInt8}</code> for <code class="notranslate">pair1</code> and <code class="notranslate">pair2</code>, while in <code class="notranslate">pair3</code> they are inferred as <code class="notranslate">Int</code> and <code class="notranslate">Union{Int8,UInt8}</code> as expected.</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; a = (&quot;foo&quot; =&gt; &quot;bar&quot;, &quot;baz&quot; =&gt; nothing);

julia&gt; function f(a, i)
           y = iterate(a, i)
           if y !== nothing
               (k, v), st = y
               return k, v
           end
           return y
       end

julia&gt; @code_warntype f(a, 1)"><pre class="notranslate">julia<span class="pl-k">&gt;</span> a <span class="pl-k">=</span> (<span class="pl-s"><span class="pl-pds">"</span>foo<span class="pl-pds">"</span></span> <span class="pl-k">=&gt;</span> <span class="pl-s"><span class="pl-pds">"</span>bar<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>baz<span class="pl-pds">"</span></span> <span class="pl-k">=&gt;</span> <span class="pl-c1">nothing</span>);

julia<span class="pl-k">&gt;</span> <span class="pl-k">function</span> <span class="pl-en">f</span>(a, i)
           y <span class="pl-k">=</span> <span class="pl-c1">iterate</span>(a, i)
           <span class="pl-k">if</span> y <span class="pl-k">!==</span> <span class="pl-c1">nothing</span>
               (k, v), st <span class="pl-k">=</span> y
               <span class="pl-k">return</span> k, v
           <span class="pl-k">end</span>
           <span class="pl-k">return</span> y
       <span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@code_warntype</span> <span class="pl-c1">f</span>(a, <span class="pl-c1">1</span>)</pre></div>
<p dir="auto">infers to <code class="notranslate">Union{Nothing, Tuple{Union{Nothing, String},Union{Nothing, String}}}</code> In particular, <code class="notranslate">k</code> is inferred as <code class="notranslate">  k::Union{Nothing, String}</code> but it could maybe be inferrable as a <code class="notranslate">String</code>.</p>