So I was trying to find the type of something like a Dict(1=>[:a=>1], 2=>[:b=>2])
for function argument type specification and it’s easy to see that since the key values are Vector{<:Pair}
, the Dict is a Dict{Int64, <:Vector{<:Pair}}
:
julia> t1 = typeof(Dict(1=>[:a=>1], 2=>[:b=>2]))
Dict{Int64, Vector{Pair{Symbol, Int64}}}
julia> supertypes(t1)
(Dict{Int64, Vector{Pair{Symbol, Int64}}}, AbstractDict{Int64, Vector{Pair{Symbol, Int64}}}, Any)
julia> t2 = Dict{Int64, <:Vector{<:Pair}}
Dict{Int64, var"#s18"} where var"#s18"<:(Vector{var"#s19"} where var"#s19"<:Pair)
julia> t1 <: t2
true
julia> [:a=>1] isa Vector{<:Pair}
true
In the above case, as I demonstrated, the key values in the Pair
Vector
element are all Int
(e.g. 1
in :a=>1
) but I don’t think if I relax the type constrain (to Any
or something) the t1 <: t2
relation would fail since those vectors are still Vector{<:Pair}
:
julia> ([:a=>1], [:c=>3.0]) isa Tuple{Vararg{Vector{<:Pair}}}
true
However, I got the following result:
julia> t3 = typeof(Dict(1=>[:a=>1], 3=>[:c=>3.0]))
Dict{Int64, Vector{T} where T}
julia> t3 <: t2
false
where the type system directly marks the Vector{<:Pair}
as Vector{T} where T
. Am I missing something here or is this a bug? Thank you!