From 1667e05f62c6b9dd581547a5ca7128963fe11899 Mon Sep 17 00:00:00 2001 From: Rene Donner Date: Tue, 4 Aug 2015 17:41:54 +0200 Subject: [PATCH] fix #12451 by providing a better error message --- base/dict.jl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/base/dict.jl b/base/dict.jl index d19d9ed448a055..5dc216230ec6dd 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -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)