JuliaCollections / JuliaCollections/DataStructures.jl

`convert` breaks DefaultOrderedDict

Open
#610 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Julia
Stars
745
Forks
261
PR merge metrics
No merged PRs in 30d

Description

julia> using DataStructures

julia> di = DefaultOrderedDict(()->Ref(2))
DefaultOrderedDict{Any,Any,var"#151#152"} with 0 entries

julia> di2 = convert(DefaultOrderedDict{Int, Ref}, di)   # the third parameter is clearly wrong
DefaultOrderedDict{Int64,Ref,DefaultOrderedDict{Any,Any,var"#151#152"}} with 0 entries

julia> di2[1]
ERROR: MethodError: Cannot `convert` an object of type 
  DefaultOrderedDict{Any,Any,var"#151#152"} to an object of type 
  Ref
Closest candidates are:
  convert(::Type{Ref}, ::Union{CategoricalArrays.CategoricalString{R}, CategoricalArrays.CategoricalValue{T,R} where T} where R) at /Users/cedric/.julia/packages/CategoricalArrays/dmrjI/src/value.jl:93
  convert(::Type{S}, ::T) where {S, T<:(Union{CategoricalArrays.CategoricalString{R}, CategoricalArrays.CategoricalValue{T,R} where T} where R)} at /Users/cedric/.julia/packages/CategoricalArrays/dmrjI/src/value.jl:103
  convert(::Type{T}, ::T) where T at essentials.jl:171
  ...
Stacktrace:
 [1] get!(::OrderedDict{Int64,Ref}, ::Int64, ::DefaultOrderedDict{Any,Any,var"#151#152"}) at /Users/cedric/.julia/packages/OrderedCollections/E21Rb/src/ordered_dict.jl:323
 [2] getindex at /Users/cedric/.julia/packages/DataStructures/3eQgj/src/default_dict.jl:69 [inlined]
 [3] getindex(::DefaultOrderedDict{Int64,Ref,DefaultOrderedDict{Any,Any,var"#151#152"}}, ::Int64) at /Users/cedric/.julia/packages/DataStructures/3eQgj/src/delegate.jl:21
 [4] top-level scope at REPL[28]:1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the conversion in the Julia REPL, then inspect src/default_dict.jl around line 69, src/delegate.jl around line 21, and OrderedCollections' ordered_dict.jl around line 323. Trace why the converted default value has the wrong type parameter; done means indexing the converted dictionary returns the intended Ref value without a MethodError.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.