<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; @generated function generatedfoo(T)
           :(return $T)
       end
generatedfoo (generic function with 1 method)

julia&gt; (@which generatedfoo(1)).source
ERROR: UndefRefError: access to undefined reference"><pre class="notranslate"><code class="notranslate">julia&gt; @generated function generatedfoo(T)
           :(return $T)
       end
generatedfoo (generic function with 1 method)

julia&gt; (@which generatedfoo(1)).source
ERROR: UndefRefError: access to undefined reference
</code></pre></div>
<p dir="auto">It doesn't make much sense to me to not have this here. It's what the user wrote, after all, even if you have to look at <code class="notranslate">isstaged</code> to properly interpret it.</p>
<p dir="auto">The following code seems to leak the scope of the variable <code class="notranslate">x</code>:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="try
    for i in 0:0
        x = i
    end
    println(&quot;first: $x&quot;)
catch err
    println(err)
end

try
    for i in 1:1
        x = i
    end
    println(&quot;second: $x&quot;)
catch err
    println(err)
end"><pre class="notranslate"><span class="pl-k">try</span>
    <span class="pl-k">for</span> i <span class="pl-k">in</span> <span class="pl-c1">0</span><span class="pl-k">:</span><span class="pl-c1">0</span>
        x <span class="pl-k">=</span> i
    <span class="pl-k">end</span>
    <span class="pl-c1">println</span>(<span class="pl-s"><span class="pl-pds">"</span>first: <span class="pl-v">$x</span><span class="pl-pds">"</span></span>)
<span class="pl-k">catch</span> err
    <span class="pl-c1">println</span>(err)
<span class="pl-k">end</span>

<span class="pl-k">try</span>
    <span class="pl-k">for</span> i <span class="pl-k">in</span> <span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">1</span>
        x <span class="pl-k">=</span> i
    <span class="pl-k">end</span>
    <span class="pl-c1">println</span>(<span class="pl-s"><span class="pl-pds">"</span>second: <span class="pl-v">$x</span><span class="pl-pds">"</span></span>)
<span class="pl-k">catch</span> err
    <span class="pl-c1">println</span>(err)
<span class="pl-k">end</span></pre></div>
<p dir="auto">output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="UndefVarError(:x)
second: 1"><pre class="notranslate"><code class="notranslate">UndefVarError(:x)
second: 1
</code></pre></div>
<p dir="auto">The first <code class="notranslate">UndefVarError</code> makes sense since the scope of <code class="notranslate">x</code> is limited in the <code class="notranslate">for</code> loop. But the second time, now <code class="notranslate">x</code> gets visible even in the outside of the <code class="notranslate">for</code> loop. I couldn't explain the change of behavior, so I filed this issue.</p>
<p dir="auto">The version I used is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; versioninfo()
Julia Version 0.4.0-dev+2304
Commit 8cea71e* (2014-12-29 02:07 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i5-4288U CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3"><pre class="notranslate"><code class="notranslate">julia&gt; versioninfo()
Julia Version 0.4.0-dev+2304
Commit 8cea71e* (2014-12-29 02:07 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i5-4288U CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
</code></pre></div>