Optional parameter causes type instability

Using @code_warntype,

function f(x::Float64, T=Float64 )
           T(x)
end

passes with flying colors, but

function f(x::Float64; T=Float64)
           T(x)
end

causes mayhem. Why?

second case is not optional parameter and keyword arguments don’t participate in multi-dispatching:
https://docs.julialang.org/en/v1/manual/methods/#Note-on-Optional-and-keyword-Arguments

1 Like