I don’t understand the dispatching of the functions defined below
f(a::Int, x::AbstractArray, t = "test") = "array"
f(a::Int, x::AbstractRange{<:Integer}, t) = "range"
f(args...) = f(2, args...)
f(1:10)
and f(2, 1:10)
result in "range"
, although t is not an optional argument and I would expect that therefore f(a::Int, x::AbstractArray, t = "test")
is called.
Interestingly, @which f(2, 1:10)
outputs the expected f(a::Int64, x::AbstractArray)
Any ideas, why this happens?
P.S.:
methods(f)
results in
f(a::Int64, x::AbstractRange{#s1} where #s1<:Integer, t) in Main at In[1]:2
f(a::Int64, x::AbstractArray) in Main at In[1]:1
f(a::Int64, x::AbstractArray, t) in Main at In[1]:1
f(args...) in Main at In[1]:3