diff --git a/base/deprecated.jl b/base/deprecated.jl index 1da2517be797dd..4f0514f3c6755c 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -189,3 +189,9 @@ const None = Union() @deprecate median(v::AbstractArray; checknan::Bool=true) median(v) @deprecate median(v::AbstractArray, region; checknan::Bool=true) median(v, region) @deprecate median!(v::AbstractVector; checknan::Bool=true) median!(v) + +@deprecate Dict{K,V}(ks::AbstractArray{K}, vs::AbstractArray{V}) Dict{K,V}(zip(ks, vs)) +@deprecate Dict{K,V}(ks::(K...), vs::(V...)) Dict{K,V}(zip(ks, vs)) +@deprecate Dict{K}(ks::(K...), vs::Tuple) Dict{K,Any}(zip(ks, vs)) +@deprecate Dict{V}(ks::Tuple, vs::(V...)) Dict{Any,V}(zip(ks, vs)) +@deprecate Dict(ks, vs) Dict{Any,Any}(zip(ks, vs)) diff --git a/base/dict.jl b/base/dict.jl index 0a4a319e7fce8d..56e2568a10ca7d 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -341,18 +341,23 @@ Dict(kv::()) = Dict() const AnyDict = Dict{Any,Any} # TODO: this can probably be simplified using `eltype` as a THT (Tim Holy trait) -Dict{K,V}(kv::((K,V)...,)) = Dict{K,V}(kv) -Dict{K }(kv::((K,Any)...,)) = Dict{K,Any}(kv) -Dict{V }(kv::((Any,V)...,)) = Dict{Any,V}(kv) -Dict{K,V}(kv::(Pair{K,V}...,)) = Dict{K,V}(kv) -Dict (kv::(Pair...,)) = Dict{Any,Any}(kv) +Dict{K,V}(kv::((K,V)...,)) = Dict{K,V}(kv) +Dict{K }(kv::((K,Any)...,)) = Dict{K,Any}(kv) +Dict{V }(kv::((Any,V)...,)) = Dict{Any,V}(kv) +Dict (kv::((Any,Any)...,)) = Dict{Any,Any}(kv) +Dict{K,V}(kv::(Pair{K,V}...,)) = Dict{K,V}(kv) +Dict{K} (kv::(Pair{K}...,)) = Dict{K,Any}(kv) +Dict{V} (kv::(Pair{TypeVar(:K),V}...,)) = Dict{Any,V}(kv) +Dict (kv::(Pair...,)) = Dict{Any,Any}(kv) Dict{K,V}(kv::AbstractArray{(K,V)}) = Dict{K,V}(kv) Dict{K,V}(kv::AbstractArray{Pair{K,V}}) = Dict{K,V}(kv) Dict{K,V}(kv::Associative{K,V}) = Dict{K,V}(kv) -Dict{K,V}(ps::Pair{K,V}...) = Dict{K,V}(ps) -Dict (ps::Pair...) = Dict{Any,Any}(ps) +Dict{K,V}(ps::Pair{K,V}...) = Dict{K,V}(ps) +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)) dict_with_eltype{K,V}(kv, ::Type{(K,V)}) = Dict{K,V}(kv) diff --git a/test/collections.jl b/test/collections.jl index 3543c1430e826b..11a4c6be13c558 100644 --- a/test/collections.jl +++ b/test/collections.jl @@ -57,6 +57,40 @@ end _d = Dict("a"=>0) @test isa([k for k in filter(x->length(x)==1, collect(keys(_d)))], Vector{Any}) +let + d = Dict(((1, 2), (3, 4))) + @test d[1] === 2 + @test d[3] === 4 + d2 = Dict(1 => 2, 3 => 4) + d3 = Dict((1 => 2, 3 => 4)) + @test d == d2 == d3 + @test typeof(d) == typeof(d2) == typeof(d3) == Dict{Int,Int} + + d = Dict(((1, 2), (3, "b"))) + @test d[1] === 2 + @test d[3] == "b" + d2 = Dict(1 => 2, 3 => "b") + d3 = Dict((1 => 2, 3 => "b")) + @test d == d2 == d3 + @test typeof(d) == typeof(d2) == typeof(d3) == Dict{Int,Any} + + d = Dict(((1, 2), ("a", 4))) + @test d[1] === 2 + @test d["a"] === 4 + d2 = Dict(1 => 2, "a" => 4) + d3 = Dict((1 => 2, "a" => 4)) + @test d == d2 == d3 + @test typeof(d) == typeof(d2) == typeof(d3) == Dict{Any,Int} + + d = Dict(((1, 2), ("a", "b"))) + @test d[1] === 2 + @test d["a"] == "b" + d2 = Dict(1 => 2, "a" => "b") + d3 = Dict((1 => 2, "a" => "b")) + @test d == d2 == d3 + @test typeof(d) == typeof(d2) == typeof(d3) == Dict{Any,Any} +end + # issue #1821 let d = Dict{UTF8String, Vector{Int}}()