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

MethodError for dictionary #12

Closed
ivirshup opened this issue Feb 20, 2020 · 1 comment
Closed

MethodError for dictionary #12

ivirshup opened this issue Feb 20, 2020 · 1 comment

Comments

@ivirshup
Copy link

ivirshup commented Feb 20, 2020

Using v0.2.1 and julia v1.3.1, I've run into a method error when trying to construct a dictionary from an array I'm pretty sure should work. Here's a reduced example:

julia> using Dictionaries

julia> a = ["a" => [1,2,3], "b" => ['a', 'b', 'c']]
2-element Array{Pair{String,Array{T,1} where T},1}:
 "a" => [1, 2, 3]      
 "b" => ['a', 'b', 'c']

julia> b = convert(Array{Pair{String,_A} where _A,1}, a)
2-element Array{Pair{String,_A} where _A,1}:
 Pair{String,Array{T,1} where T}("a", [1, 2, 3])      
 Pair{String,Array{T,1} where T}("b", ['a', 'b', 'c'])

julia> dictionary(a) # Works fine
2-element HashDictionary{String,Array{T,1} where T}
 "b" │ ['a', 'b', 'c']
 "a" │ [1, 2, 3]

julia> dictionary(b)
ERROR: MethodError: no method matching _dictionary(::Type{Pair{String,_A} where _A}, ::Array{Pair{String,_A} where _A,1})
Closest candidates are:
  _dictionary(::Type{Pair{I,T}}, ::Any) where {I, T} at /Users/isaac/.julia/packages/Dictionaries/cZc5T/src/HashDictionary.jl:117
Stacktrace:
 [1] dictionary(::Array{Pair{String,_A} where _A,1}) at /Users/isaac/.julia/packages/Dictionaries/cZc5T/src/HashDictionary.jl:111
 [2] top-level scope at REPL[9]:1

julia> typeof(a)
Array{Pair{String,Array{T,1} where T},1}

julia> typeof(b)
Array{Pair{String,_A} where _A,1}

Ah, I think I see what's happening now:

julia> Tuple{eltype(b), typeof(b)} <: Tuple{Pair{I, T} where {I, T}, Any}
true

julia> Tuple{Type{eltype(b)}, typeof(b)} <: Tuple{Type{Pair{I, T} where {I, T}}, Any}
false

But I can't seem to fix it without making inference much worse. Hm.


dictionary(Dict(b)) does the trick as a workaround.

@andyferris
Copy link
Owner

Thank you for the bug report and sorry for the delay!

This was fixed by #13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants