Skip to content

Misleading warning on ambiguous method definition #5384

@burrowsa

Description

@burrowsa

If I do this:

immutable Foo{T} end
=={T}(lhs::Foo{T},rhs::Foo{T}) = lhs===rhs
=={T}(lhs::Foo{T},rhs::Any) = false
=={T}(lhs::Any,rhs::Foo{T}) = false

I get this warning

Warning: New definition
==(Any,Foo{T}) at none:1
is ambiguous with:
==(Foo{T},Any) at none:1.
To fix, define
==(Foo{T},Foo{T})
before the new definition.

even though I have already defined ==(Foo{T},Foo{T}).

After a trying lots of alternatives it would seem that the solution is to do:

immutable Foo{T} end
=={T1,T2}(lhs::Foo{T1},rhs::Foo{T2}) = lhs===rhs
=={T}(lhs::Foo{T},rhs::Any) = false
=={T}(lhs::Any,rhs::Foo{T}) = false

So I think that the warning is misleading and should be changed to:

Warning: New definition
==(Any,Foo{T}) at none:1
is ambiguous with:
==(Foo{T},Any) at none:1.
To fix, define
==(Foo{T1},Foo{T2})
before the new definition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    types and dispatchTypes, subtyping and method dispatch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions