Skip to content
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

subtype error with KV<:Union{K,Ref{K}} alternate constraint #40865

Closed
AzamatB opened this issue May 19, 2021 · 1 comment · Fixed by #48441
Closed

subtype error with KV<:Union{K,Ref{K}} alternate constraint #40865

AzamatB opened this issue May 19, 2021 · 1 comment · Fixed by #48441
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@AzamatB
Copy link
Contributor

AzamatB commented May 19, 2021

The following works as expected:

function f(
    x::AbstractDict{KV,Tuple{Int}},
    y::Union{Set{K},Dict{K,V}},
) where {K,V, KV <: Union{K,Tuple{K,V}}}
    return "done"
end

K = Int
x = Dict{K,Tuple{Int}}()
y = Set{K}()

julia> f(x, y)
"done"

Now replace K = Int with K = Tuple{Int,Int} and now it throws MethodError: no method matching

@vtjnash vtjnash added the types and dispatch Types, subtyping and method dispatch label May 19, 2021
@vtjnash
Copy link
Member

vtjnash commented May 19, 2021

Here's a reduction into the type domain:

julia> Tuple{Set{Ref{Int}}, Set{Ref{Int}}} <: Tuple{Set{KV}, Set{K}} where {K,KV<:Union{K,Ref{K}}}
false

julia> Tuple{Set{Ref{Int}}, Set{Ref{Int}}} <: Tuple{Set{KV}, Set{K}} where {K,KV<:K}
true

julia> Tuple{Set{Val{Int}}, Set{Val{Int}}} <: Tuple{Set{KV}, Set{K}} where {K,KV<:Union{K,Ref{K}}}
true

julia> Tuple{Set{Val{Int}}, Set{Val{Int}}} <: Tuple{Set{KV}, Set{K}} where {K,KV<:Union{K,Val{K}}}
false

Note how widening KV with that Union mislead subtyping into reporting false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants