-
Notifications
You must be signed in to change notification settings - Fork 30
defining a method of a generic comparison with one argument unconstrained in a package is a bug #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The strategy I use for most operators (not only |
This is not true. The extra method obviously has no effect on the examples I give above. |
To be specific: julia> struct A end # in one package
julia> function Base.:(==)(::A, ::A) end
julia> function Base.:(==)(::Any, ::A) end
julia> function Base.:(==)(::A, ::Any) end
julia> struct B end # in another package
julia> function Base.:(==)(::B, ::B) end
julia> function Base.:(==)(::Any, ::B) end
julia> function Base.:(==)(::B, ::Any) end
julia> A() == B()
ERROR: MethodError: ==(::A, ::B) is ambiguous.
Candidates:
==(::A, ::Any)
@ Main REPL[4]:1
==(::Any, ::B)
@ Main REPL[7]:1
Possible fix, define
==(::A, ::B)
Stacktrace:
[1] top-level scope
@ REPL[9]:1 |
Sorry I didn't read in detail, yes indeed, it won't work of two packages do it. Would the suggestion in #290 (comment) address the concern ? |
The fact that an important (for the ecosystem) registered package failed to follow the advice/rule provided in the change is evidence to the claim that adding these docs is important. Ref: * JuliaAlgebra/MultivariatePolynomials.jl#310 Fixes JuliaLang#55866
FYI: created a doc PR for JuliaLang/julia regarding a generalization of the issue here, to warn against it in the Manual: Perhaps take a look at it if there's time, it could be good to review if something is not clear or otherwise.
I believe so, yeah. |
Defining a
==
method with one of the arguments untyped should never be done in a registered package. This is done here, and in some other places:MultivariatePolynomials.jl/src/comparison.jl
Lines 118 to 119 in 674b38f
The reason that's a bug is that that kind of method signature will be ambiguous with regards to methods defined in other packages. Observe, fresh REPL session:
Or, more minimally and concretely:
I saw this on issue #290 first, but decided to open a new issue, since what I'm pointing out seems worse than invalidation of precompiled code and is not related to invalidation.
The text was updated successfully, but these errors were encountered: