-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Description
Not sure if this is a bug or a design issue, but I would argue that in method dispatch insufficient priority is given to the # of arguments. I found the following somewhat surprising:
function f(i::Integer)
println("f1")
end
function f(i::Union(Int,Integer))
println("f1union")
end
function f(i1::Integer,i2::Integer)
println("f2")
end
function f(ind::RangeIndex...)
println("fn")
end
julia> f(3)
fn
julia> f(uint(3))
f1union
julia> f(convert(Integer,3))
fn
julia> function f(i::Int)
println("f1Int")
end
julia> f(3)
f1Int
So even the explicit f(i::Union(Int,Integer))
is not enough to "override" the generic f(ind::RangeIndex...)
variant; it requires defining an Int
-specific variant. The Int
-specific variant can be defined before or after the others, it does not matter which.
Metadata
Metadata
Assignees
Labels
No labels