-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Specificity of function not clear #46598
Comments
Note that this has nothing to do with constructors. The same specificity can be exercised with julia> abstract type A end
julia> abstract type B <: A end
julia> struct S<:B end
julia> struct R<:B end
julia> foo(::Type{T}, x::T) where {T <: A} = 1
foo (generic function with 1 method)
julia> foo(::Type{T}, x::B) where {T <: B} = 2
foo (generic function with 2 methods)
julia> foo(S, R())
2
julia> foo(R, R())
2 To quote from https://docs.julialang.org/en/v1/devdocs/types/#Subtyping-and-method-sorting: "If a is a strict subtype of b, then it is automatically considered more specific. From there, Here we have two conflicting aspects: As The fix/workaround would be to define foo(::Type{T}, x::T) where {T <: B} = 3 or function (::Type{T})(f::T) where {T<: B}
@info "no copy"
f
end for your case. |
Hmm okay, thanks! Are these less formal rules documented somewhere then? Because to me at least, it should be opposite specificity.. |
Duplicate of #23740, I think |
Interestingly:
I would imagine this should behave the same, but apparently not. |
More-specific first ignores TypeVar. It sees that the first case requires both args to be |
I have the following constructors
Now if I execute
I would expect that
R(r)
calls the first constructor but that is not the case. It seems to me that the first will always be more specific..If anything I cannot find any info on the topic in the documentation. Maybe something needs clearing up in the diagonal types section..
The text was updated successfully, but these errors were encountered: