<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="module M1
type T1
y
end
foo(x::Int) = 10
foo(x::T1) = foo(x.y)
end

@show code_typed(M1.foo, (M1.T1,))"><pre class="notranslate"><span class="pl-k">module</span> M1
type T1
y
<span class="pl-k">end</span>
<span class="pl-en">foo</span>(x<span class="pl-k">::</span><span class="pl-c1">Int</span>) <span class="pl-k">=</span> <span class="pl-c1">10</span>
<span class="pl-en">foo</span>(x<span class="pl-k">::</span><span class="pl-c1">T1</span>) <span class="pl-k">=</span> <span class="pl-c1">foo</span>(x<span class="pl-k">.</span>y)
<span class="pl-k">end</span>

<span class="pl-c1">@show</span> <span class="pl-c1">code_typed</span>(M1<span class="pl-k">.</span>foo, (M1<span class="pl-k">.</span>T1,))</pre></div>
<p dir="auto">gives</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="code_typed(M1.foo,(M1.T1,)) = Any[:($(Expr(:lambda, Any[:x], Any[Any[],Any[Any[:x,M1.T1,0]],Any[]], :(begin  # /home/mlubin/test2.jl, line 8:
        return foo((top(getfield))(x::M1.T1,:y))::Int64
    end::Int64))))]"><pre class="notranslate"><code class="notranslate">code_typed(M1.foo,(M1.T1,)) = Any[:($(Expr(:lambda, Any[:x], Any[Any[],Any[Any[:x,M1.T1,0]],Any[]], :(begin  # /home/mlubin/test2.jl, line 8:
        return foo((top(getfield))(x::M1.T1,:y))::Int64
    end::Int64))))]
</code></pre></div>
<p dir="auto">on Julia 0.4.</p>
<p dir="auto">This is incorrect, we can't infer anything about the return type here, since <code class="notranslate">foo</code> could be extended later and <code class="notranslate">x.y</code> doesn't need to be an <code class="notranslate">Int</code>.</p>
<p dir="auto">if I define a function d2 before a function d1 which calls d2 then change d2, d1 uses the old definition for d2.<br>
I assume this is because it is all precompiled, but maybe there should be a note warning of this? Or would it be possible to replace the old definition with a longjmp to the new one?<br>
(Mostly important for the REPL, since I don't always do a full load)</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; function d2()
       a
       end

julia&gt; function d()
         d2()
       end

julia&gt; d()
in d: a not defined

julia&gt; function d2()
       b=2
       end

julia&gt; d()
in d: a not defined

julia&gt; d2
Methods for generic function d2
d2() at prompt:2

julia&gt; function d()
         d2()
       end

julia&gt; d()
2"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-k">function</span> <span class="pl-en">d2</span>()
       a
       <span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> <span class="pl-k">function</span> <span class="pl-en">d</span>()
         <span class="pl-c1">d2</span>()
       <span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">d</span>()
in d<span class="pl-k">:</span> a not defined

julia<span class="pl-k">&gt;</span> <span class="pl-k">function</span> <span class="pl-en">d2</span>()
       b<span class="pl-k">=</span><span class="pl-c1">2</span>
       <span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">d</span>()
in d<span class="pl-k">:</span> a not defined

julia<span class="pl-k">&gt;</span> d2
Methods <span class="pl-k">for</span> generic <span class="pl-k">function</span> d2
<span class="pl-c1">d2</span>() at prompt<span class="pl-k">:</span><span class="pl-c1">2</span>

julia<span class="pl-k">&gt;</span> <span class="pl-k">function</span> <span class="pl-en">d</span>()
         <span class="pl-c1">d2</span>()
       <span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">d</span>()
<span class="pl-c1">2</span></pre></div>