Skip to content

Commit fe59346

Browse files
authored
Left fold ImmutableDict(args::Pair...) (#35871)
Currently, the behavior of `Dict(pairs...)` and `Base.ImmutableDict(pairs...)` are different: julia> Dict(:a => 1, :a => 2)[:a] 2 julia> Base.ImmutableDict(:a => 1, :a => 2)[:a] 1 This PR fixes the latter to return 2.
1 parent cb2e8c8 commit fe59346

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

base/dict.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ Create a new entry in the `ImmutableDict` for a `key => value` pair
742742
ImmutableDict
743743
ImmutableDict(KV::Pair{K,V}) where {K,V} = ImmutableDict{K,V}(KV[1], KV[2])
744744
ImmutableDict(t::ImmutableDict{K,V}, KV::Pair) where {K,V} = ImmutableDict{K,V}(t, KV[1], KV[2])
745-
ImmutableDict(KV::Pair, rest::Pair...) = ImmutableDict(ImmutableDict(rest...), KV)
745+
ImmutableDict(KV::Pair, rest::Pair...) = ImmutableDict(ImmutableDict(KV), rest...)
746746

747747
function in(key_value::Pair, dict::ImmutableDict, valcmp=(==))
748748
key, value = key_value

test/dict.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,8 @@ import Base.ImmutableDict
722722
v = [k1 => v1, k2 => v2]
723723
d5 = ImmutableDict(v...)
724724
@test d5 == d2
725-
@test collect(d5) == v
725+
@test reverse(collect(d5)) == v
726+
@test ImmutableDict(:a => 1, :a => 2)[:a] == 2
726727

727728
@test !haskey(ImmutableDict(-0.0=>1), 0.0)
728729
end

0 commit comments

Comments
 (0)