We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents ca509cd + a448b0d commit 1ac30c3Copy full SHA for 1ac30c3
base/dict.jl
@@ -152,11 +152,20 @@ function Dict(kv)
152
end
153
154
155
-dict_with_eltype{K,V}(kv, ::Type{Tuple{K,V}}) = Dict{K,V}(kv)
156
-dict_with_eltype{K,V}(kv, ::Type{Pair{K,V}}) = Dict{K,V}(kv)
+typealias TP{K,V} Union{Type{Tuple{K,V}},Type{Pair{K,V}}}
+
157
+dict_with_eltype{K,V}(kv, ::TP{K,V}) = Dict{K,V}(kv)
158
+dict_with_eltype{K,V}(kv::Generator, ::TP{K,V}) = Dict{K,V}(kv)
159
dict_with_eltype{K,V}(::Type{Pair{K,V}}) = Dict{K,V}()
160
dict_with_eltype(::Type) = Dict()
161
dict_with_eltype(kv, t) = grow_to!(dict_with_eltype(_default_eltype(typeof(kv))), kv)
162
+function dict_with_eltype(kv::Generator, t)
163
+ T = _default_eltype(typeof(kv))
164
+ if T <: Union{Pair,NTuple{2}} && isleaftype(T)
165
+ return dict_with_eltype(kv, T)
166
+ end
167
+ return grow_to!(dict_with_eltype(T), kv)
168
+end
169
170
# this is a special case due to (1) allowing both Pairs and Tuples as elements,
171
# and (2) Pair being invariant. a bit annoying.
test/dict.jl
@@ -138,7 +138,7 @@ end
138
@test first(Dict(:f=>2)) == (:f=>2)
139
140
# constructing Dicts from iterators
141
-let d = Dict(i=>i for i=1:3)
+let d = @inferred Dict(i=>i for i=1:3)
142
@test isa(d, Dict{Int,Int})
143
@test d == Dict(1=>1, 2=>2, 3=>3)
144
0 commit comments