TypeError typeassert for custom types

I don't understand the following behavior

a = [1,2,3]
a::Vector  # works

d = Dict(0=>a)
typealias DictVector{K,V} Dict{K, Vector{V}}
d::DictVector  # fails

      

the error is as follows

TypeError: typeassert: expected Dict{K,Array{V,1}}, got 
 Dict{Int64,Array{Int64,1}}
  in include_string(::String, ::String) at loading.jl:441
  in eval(::Module, ::Any) at boot.jl:234
  in (::Atom.##65#68)() at eval.jl:40
  in withpath(::Atom.##65#68, ::Void) at utils.jl:30
  in withpath(::Function, ::Void) at eval.jl:46
  in macro expansion at eval.jl:109 [inlined]
  in (::Atom.##64#67{Dict{String,Any}})() at task.jl:60

      

however the vector itself is how typealias Vector{T} Array{T,1}

, so what is the crucial difference between the two cases?

Any clarification is much appreciated

+3


source to share


1 answer


You are right that you have to work. It looks like it was a bug in the old 0.5 type system. This is fixed in the upcoming version 0.6.

Here's a possible workaround for 0.5:



julia> typealias DictVector{K,V<:Vector} Dict{K,V}
Dict{K,V<:Array{T,1}}

julia> d::DictVector
Dict{Int64,Array{Int64,1}} with 1 entry:
  0 => [1,2,3]

julia> isa(d, DictVector)
true

      

+4


source







All Articles