<p dir="auto">Consider the following function <code class="notranslate">f</code>:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function f()
    if rand(Bool)
        idxs = [[1,2],[1,2,3]]
    else
        idxs = [[1,2],[1,2,3]]
    end

    return idxs
end"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">f</span>()
    <span class="pl-k">if</span> <span class="pl-c1">rand</span>(Bool)
        idxs <span class="pl-k">=</span> [[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>],[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>]]
    <span class="pl-k">else</span>
        idxs <span class="pl-k">=</span> [[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>],[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>]]
    <span class="pl-k">end</span>

    <span class="pl-k">return</span> idxs
<span class="pl-k">end</span></pre></div>
<p dir="auto">As well as the functionally identical variation <code class="notranslate">g</code>:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function g()
    if rand(Bool)
        idxs = [[1,2],[1,2,3]]
    else
        idxs = [[1,2],[1,2,3]]
    end

    [idxs[j] for j in 1:length(idxs)]
    return idxs
end"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">g</span>()
    <span class="pl-k">if</span> <span class="pl-c1">rand</span>(Bool)
        idxs <span class="pl-k">=</span> [[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>],[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>]]
    <span class="pl-k">else</span>
        idxs <span class="pl-k">=</span> [[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>],[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>]]
    <span class="pl-k">end</span>

    [idxs[j] <span class="pl-k">for</span> j <span class="pl-k">in</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">length</span>(idxs)]
    <span class="pl-k">return</span> idxs
<span class="pl-k">end</span></pre></div>
<p dir="auto">Here, <code class="notranslate">f</code> will infer perfectly fine - but adding an iterator over <code class="notranslate">idxs</code> in <code class="notranslate">g</code> (which, notably, is not used for anything) will cause inference to give up, inferring <code class="notranslate">Any</code> as return value. Effectively, using the iterator poisons everything.</p>
<p dir="auto">Defining and using variables this way is definitely an anti-pattern (and can be avoided in several ways) but since<code class="notranslate">f</code> works just fine (and e.g., is not disallowed) it struck me as unintended that <code class="notranslate">g</code> does not.</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="using Images: realtype

function ifi{T&lt;:Real,K,N}(img::AbstractArray{T,N}, kern::AbstractArray{K,N}, border::AbstractString, value)
    if border == &quot;circular&quot; &amp;&amp; size(img) == size(kern)
        out = real(ifftshift(ifft(fft(img).*fft(kern))))
    elseif border != &quot;inner&quot;
        prepad  = [div(size(kern,i)-1, 2) for i = 1:N]
        postpad = [div(size(kern,i),   2) for i = 1:N]
        fullpad = [nextprod([2,3], size(img,i) + prepad[i] + postpad[i]) - size(img, i) - prepad[i] for i = 1:N]
        A = padarray(img, prepad, fullpad, border, convert(T, value))
        krn = zeros(typeof(one(T)*one(K)), size(A))
        indexesK = ntuple(d-&gt;[size(krn,d)-prepad[d]+1:size(krn,d);1:size(kern,d)-prepad[d]], N)::NTuple{N,Vector{Int}}
        AF = ifft(fft(A).*fft(krn))
        out = Array(realtype(eltype(AF)), size(img))
    end
    out
end"><pre class="notranslate"><span class="pl-k">using</span> Images<span class="pl-k">:</span> realtype

<span class="pl-k">function</span> <span class="pl-en">ifi</span><span class="pl-c1">{T&lt;:Real,K,N}</span>(img<span class="pl-k">::</span><span class="pl-c1">AbstractArray{T,N}</span>, kern<span class="pl-k">::</span><span class="pl-c1">AbstractArray{K,N}</span>, border<span class="pl-k">::</span><span class="pl-c1">AbstractString</span>, value)
    <span class="pl-k">if</span> border <span class="pl-k">==</span> <span class="pl-s"><span class="pl-pds">"</span>circular<span class="pl-pds">"</span></span> <span class="pl-k">&amp;&amp;</span> <span class="pl-c1">size</span>(img) <span class="pl-k">==</span> <span class="pl-c1">size</span>(kern)
        out <span class="pl-k">=</span> <span class="pl-c1">real</span>(<span class="pl-c1">ifftshift</span>(<span class="pl-c1">ifft</span>(<span class="pl-c1">fft</span>(img)<span class="pl-k">.*</span><span class="pl-c1">fft</span>(kern))))
    <span class="pl-k">elseif</span> border <span class="pl-k">!=</span> <span class="pl-s"><span class="pl-pds">"</span>inner<span class="pl-pds">"</span></span>
        prepad  <span class="pl-k">=</span> [<span class="pl-c1">div</span>(<span class="pl-c1">size</span>(kern,i)<span class="pl-k">-</span><span class="pl-c1">1</span>, <span class="pl-c1">2</span>) <span class="pl-k">for</span> i <span class="pl-k">=</span> <span class="pl-c1">1</span><span class="pl-k">:</span>N]
        postpad <span class="pl-k">=</span> [<span class="pl-c1">div</span>(<span class="pl-c1">size</span>(kern,i),   <span class="pl-c1">2</span>) <span class="pl-k">for</span> i <span class="pl-k">=</span> <span class="pl-c1">1</span><span class="pl-k">:</span>N]
        fullpad <span class="pl-k">=</span> [<span class="pl-c1">nextprod</span>([<span class="pl-c1">2</span>,<span class="pl-c1">3</span>], <span class="pl-c1">size</span>(img,i) <span class="pl-k">+</span> prepad[i] <span class="pl-k">+</span> postpad[i]) <span class="pl-k">-</span> <span class="pl-c1">size</span>(img, i) <span class="pl-k">-</span> prepad[i] <span class="pl-k">for</span> i <span class="pl-k">=</span> <span class="pl-c1">1</span><span class="pl-k">:</span>N]
        A <span class="pl-k">=</span> <span class="pl-c1">padarray</span>(img, prepad, fullpad, border, <span class="pl-c1">convert</span>(T, value))
        krn <span class="pl-k">=</span> <span class="pl-c1">zeros</span>(<span class="pl-c1">typeof</span>(<span class="pl-c1">one</span>(T)<span class="pl-k">*</span><span class="pl-c1">one</span>(K)), <span class="pl-c1">size</span>(A))
        indexesK <span class="pl-k">=</span> <span class="pl-c1">ntuple</span>(d<span class="pl-k">-&gt;</span>[<span class="pl-c1">size</span>(krn,d)<span class="pl-k">-</span>prepad[d]<span class="pl-k">+</span><span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">size</span>(krn,d);<span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">size</span>(kern,d)<span class="pl-k">-</span>prepad[d]], N)<span class="pl-k">::</span><span class="pl-c1">NTuple{N,Vector{Int}}</span>
        AF <span class="pl-k">=</span> <span class="pl-c1">ifft</span>(<span class="pl-c1">fft</span>(A)<span class="pl-k">.*</span><span class="pl-c1">fft</span>(krn))
        out <span class="pl-k">=</span> <span class="pl-c1">Array</span>(<span class="pl-c1">realtype</span>(<span class="pl-c1">eltype</span>(AF)), <span class="pl-c1">size</span>(img))
    <span class="pl-k">end</span>
    out
<span class="pl-k">end</span></pre></div>
<p dir="auto">Test:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; @code_warntype ifi(rand(3,3), rand(3,3), &quot;replicate&quot;, 0)
Variables:
  #self#::#ifi
  img::Array{Float64,2}
  kern::Array{Float64,2}
  border::ASCIIString
  value::Int64
  prepad::Box
..."><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">@code_warntype</span> <span class="pl-c1">ifi</span>(<span class="pl-c1">rand</span>(<span class="pl-c1">3</span>,<span class="pl-c1">3</span>), <span class="pl-c1">rand</span>(<span class="pl-c1">3</span>,<span class="pl-c1">3</span>), <span class="pl-s"><span class="pl-pds">"</span>replicate<span class="pl-pds">"</span></span>, <span class="pl-c1">0</span>)
Variables<span class="pl-k">:</span>
  <span class="pl-c"><span class="pl-c">#</span>self#::#ifi</span>
  img<span class="pl-k">::</span><span class="pl-c1">Array{Float64,2}</span>
  kern<span class="pl-k">::</span><span class="pl-c1">Array{Float64,2}</span>
  border<span class="pl-k">::</span><span class="pl-c1">ASCIIString</span>
  value<span class="pl-k">::</span><span class="pl-c1">Int64</span>
  prepad<span class="pl-k">::</span><span class="pl-c1">Box</span>
<span class="pl-k">...</span></pre></div>
<p dir="auto">Now comment out the <code class="notranslate">indexesK = ...</code> line (the output of which is not used at all). Suddenly <code class="notranslate">prepad</code> is inferred as <code class="notranslate">Array{Int, 1}</code>.</p>