<p dir="auto">I observed some unexpected specialization behavior with keyword arguments.</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; function f(x; as::Type{T} = Int) where {T}
         return T(x)
       end"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-k">function</span> <span class="pl-en">f</span>(x; as<span class="pl-k">::</span><span class="pl-c1">Type{T}</span> <span class="pl-k">=</span> Int) <span class="pl-k">where</span> {T}
         <span class="pl-k">return</span> <span class="pl-c1">T</span>(x)
       <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; @code_warntype f(1, as = Float64)"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">@code_warntype</span> <span class="pl-c1">f</span>(<span class="pl-c1">1</span>, as <span class="pl-k">=</span> Float64)</pre></div>
<p dir="auto">seems to indicate that it is not really specializing, but juggling around with <code class="notranslate">DataType</code>. I would have expected this with just <code class="notranslate">as::Type = Int</code> because of some specialization heuristic I know from positional arguments.</p>
<p dir="auto">Is this intended? Or maybe <code class="notranslate">@code_warntype</code> is lying to me? Reproduced on julia 1.5 and 6 days old master.</p>
<p dir="auto">Edit: Maybe this is <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="710960273" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/37797" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/37797/hovercard" href="https://github.com/JuliaLang/julia/issues/37797">#37797</a>? Don't know enough about the internals.</p>
<p dir="auto"><code class="notranslate">@code_typed</code> (and <code class="notranslate">code_typed</code>) will sometimes report a different result than actually gets inferred if you call the function. For example:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; f1(x) = Base.typemax(x)
f1 (generic function with 1 method)

julia&gt; @code_typed f1(Int)
CodeInfo(
1 ─     return 9223372036854775807
) =&gt; Int64"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-en">f1</span>(x) <span class="pl-k">=</span> Base<span class="pl-k">.</span><span class="pl-c1">typemax</span>(x)
f1 (generic <span class="pl-k">function</span> with <span class="pl-c1">1</span> method)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">@code_typed</span> <span class="pl-c1">f1</span>(Int)
<span class="pl-c1">CodeInfo</span>(
<span class="pl-c1">1</span> ─     <span class="pl-k">return</span> <span class="pl-c1">9223372036854775807</span>
) <span class="pl-k">=&gt;</span> Int64</pre></div>
<p dir="auto">Here <code class="notranslate">@code_typed</code> shows you fully specialized code, even though in reality this call will not be specialized (it will be a dynamic dispatch to <code class="notranslate">typemax(Type{Int})</code>).</p>
<p dir="auto">xref: the documentation change here: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="477996195" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/32817" data-hovercard-type="pull_request" data-hovercard-url="/JuliaLang/julia/pull/32817/hovercard" href="https://github.com/JuliaLang/julia/pull/32817">#32817</a></p>
<blockquote>
<p dir="auto">Note that <a href="@ref"><code class="notranslate">@code_typed</code></a> and friends will always show you specialized code, even if Julia<br>
would not normally specialize that method call. You need to check the<br>
[method internals](<a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ref/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ref">@ref</a> ast-lowered-method) if you want to see whether specializations are generated<br>
when argument types are changed.</p>
</blockquote>
<hr>
<p dir="auto">Could we either change <code class="notranslate">@code_typed</code> or add a flag to <code class="notranslate">@code_typed</code> that will show you the code as julia would <em>actually</em> specialize it, instead of fully specialized to your argument type? :)</p>