Skip to content

Parameterized methods can shadow other method without error/warning #18892

@mauro3

Description

@mauro3

Parameterized methods are more specific than non-parameterized ones:

julia> g(x) = 1
g (generic function with 1 method)

julia> g{X}(x::X) = 2
g (generic function with 2 methods)

julia> g(4)
2

I don't think there is any way to call the first method of g.

Similarly for several arguments:

julia> h(x,y) = 1
h (generic function with 1 method)

julia> h{X}(x::X,y) = 2
h (generic function with 2 methods)

julia> h{X,Y}(x::X,y::Y) = 3
h (generic function with 3 methods)

julia> h{Y}(x,y::Y) = 4
h (generic function with 4 methods)

julia> h(4,5)
2

One solution is to consider above methods ambiguous and throw MethodError ... is ambiguous. on call. Another solution is to make those method definitions overwrite the previous one. Probably should be in sync with #8974.

X-ref: https://groups.google.com/d/msg/julia-users/-ldkZlbg76Q/pYRNT4eIBAAJ

Metadata

Metadata

Assignees

No one assigned

    Labels

    types and dispatchTypes, subtyping and method dispatch

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions