From e7256537644ce790c96f6099e94bd8d24406b660 Mon Sep 17 00:00:00 2001 From: ivarne Date: Thu, 11 Dec 2014 13:17:56 +0100 Subject: [PATCH 1/2] Fix #9295 Deprecate `push!(a, k, v)` in favor of `push!(a, k=>v)` because the old signature was inconsistent with the varargs version of `push!` to add multiple elements to a collection. TODO: Add tests Conflicts: base/deprecated.jl --- base/deprecated.jl | 3 +++ base/dict.jl | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/base/deprecated.jl b/base/deprecated.jl index dd44a24e7cea3..bee42c79ccc83 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -276,3 +276,6 @@ const base64 = base64encode @deprecate map!(f::Callable, dest::StridedArray, A::StridedArray, B::Number) broadcast!(f, dest, A, B) @deprecate map!(f::Callable, dest::StridedArray, A::Number, B::StridedArray) broadcast!(f, dest, A, B) + +#9295 +@deprecate push!(t::Associative, key, v) setindex!(t, v, key) diff --git a/base/dict.jl b/base/dict.jl index e2f907514dea1..9a2fd3a856bd0 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -246,7 +246,7 @@ end getindex(t::Associative, k1, k2, ks...) = getindex(t, tuple(k1,k2,ks...)) setindex!(t::Associative, v, k1, k2, ks...) = setindex!(t, v, tuple(k1,k2,ks...)) -push!(t::Associative, key, v) = setindex!(t, v, key) +push!(t::Associative, p::Pair) = setindex!(t, p.second, p.first) # hashing objects by identity From 20138be7b26a645055f69c697d855c5dfde742de Mon Sep 17 00:00:00 2001 From: Kenta Sato Date: Sat, 24 Jan 2015 13:01:24 +0900 Subject: [PATCH 2/2] add push!(Associative, vararg...) [#9295] --- base/dict.jl | 2 ++ test/dict.jl | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/base/dict.jl b/base/dict.jl index 9a2fd3a856bd0..a346d1266705d 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -247,6 +247,8 @@ getindex(t::Associative, k1, k2, ks...) = getindex(t, tuple(k1,k2,ks...)) setindex!(t::Associative, v, k1, k2, ks...) = setindex!(t, v, tuple(k1,k2,ks...)) push!(t::Associative, p::Pair) = setindex!(t, p.second, p.first) +push!(t::Associative, p::Pair, q::Pair) = push!(push!(t, p), q) +push!(t::Associative, p::Pair, q::Pair, r::Pair...) = push!(push!(push!(t, p), q), r...) # hashing objects by identity diff --git a/test/dict.jl b/test/dict.jl index 9d93c9337ab4c..96414e0e6ea6c 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -269,3 +269,18 @@ let b = Dict("フー" => 17, "バー" => 4711) @test is(typeof(merge(a, b)), Dict{UTF8String,Float64}) end + +# issue 9295 +let + d = Dict() + @test is(push!(d, 'a' => 1), d) + @test d['a'] == 1 + @test is(push!(d, 'b' => 2, 'c' => 3), d) + @test d['b'] == 2 + @test d['c'] == 3 + @test is(push!(d, 'd' => 4, 'e' => 5, 'f' => 6), d) + @test d['d'] == 4 + @test d['e'] == 5 + @test d['f'] == 6 + @test length(d) == 6 +end