Skip to content

Commit

Permalink
fix JuliaLang#12451 by providing a better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Rene Donner committed Aug 4, 2015
1 parent e66175b commit 1667e05
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,19 @@ Dict{K }(ps::Pair{K}...,) = Dict{K,Any}(ps)
Dict{V }(ps::Pair{TypeVar(:K),V}...,) = Dict{Any,V}(ps)
Dict( ps::Pair...) = Dict{Any,Any}(ps)

Dict(kv) = dict_with_eltype(kv, eltype(kv))
function Dict(kv)
try
Base.dict_with_eltype(kv, eltype(kv))
catch e
if any(x->isempty(methods(x, (typeof(kv),))), [start, next, done]) ||
!all(x->isa(x,Union{Tuple,Pair}),kv)
error("Dict(kv): kv needs to be an interator of tuples or pairs")
else
rethrow(e)
end
end
end

dict_with_eltype{K,V}(kv, ::Type{Tuple{K,V}}) = Dict{K,V}(kv)
dict_with_eltype{K,V}(kv, ::Type{Pair{K,V}}) = Dict{K,V}(kv)
dict_with_eltype(kv, t) = Dict{Any,Any}(kv)
Expand Down

0 comments on commit 1667e05

Please sign in to comment.