Skip to content

Commit

Permalink
Fix missing similar methods for Dict
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Aug 11, 2016
1 parent b066714 commit 3cfc74d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -848,3 +848,10 @@ function similar(t::ImmutableDict)
end
return t
end

_similar_for{P<:Pair}(c::Dict, ::Type{P}, itr, isz::SizeUnknown) = similar(c, P)
_similar_for{P<:Pair}(c::Dict, ::Type{P}, itr, isz::HasLength) = similar(c, P)
_similar_for{P<:Pair}(c::Dict, ::Type{P}, itr, isz::HasShape) = similar(c, P)
_similar_for(c::Associative, T, itr, ::SizeUnknown) = Array{Any}(0)
_similar_for(c::Associative, T, itr, ::HasLength) = Array{Any}(length(itr))
_similar_for(c::Associative, T, itr, ::HasShape) = Array{Any}(size(itr))
5 changes: 5 additions & 0 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ d = Dict('a'=>1, 'b'=>1, 'c'=> 3)
@test [d[k] for k in keys(d)] == [d[k] for k in eachindex(d)] ==
[v for (k, v) in d] == [d[x[1]] for (i, x) in enumerate(d)]

# generators, similar
d = Dict(:a=>"a")
@test @inferred(map(identity, d)) == d
@test @inferred(map(p->p.first=>p.second[1], d)) == Dict(:a=>'a')
@test @inferred(map(p->p.second, d)) == Any["a"]

# Issue 12451
@test_throws ArgumentError Dict(0)
Expand Down

0 comments on commit 3cfc74d

Please sign in to comment.