Skip to content

Dispatch method selection (RangeIndex... more specific than Integer?) #795

@timholy

Description

@timholy

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions