diff --git a/base/abstractdict.jl b/base/abstractdict.jl index 845dcc54f8d669..f4acbf7b4c301b 100644 --- a/base/abstractdict.jl +++ b/base/abstractdict.jl @@ -17,9 +17,9 @@ const secret_table_token = :__c782dbf1cf4d6a2e5e3865d7e95634f2e09b5902__ haskey(d::AbstractDict, k) = in(k, keys(d)) function in(p::Pair, a::AbstractDict, valcmp=(==)) - v = get(a,p[1],secret_table_token) + v = get(a, p.first, secret_table_token) if v !== secret_table_token - return valcmp(v, p[2]) + return valcmp(v, p.second) end return false end @@ -474,14 +474,16 @@ function isequal(l::AbstractDict, r::AbstractDict) end function ==(l::AbstractDict, r::AbstractDict) - l === r && return true + if l === r + return any(ismissing, values(l)) ? missing : true + end if isa(l,IdDict) != isa(r,IdDict) return false end length(l) != length(r) && return false anymissing = false for pair in l - isin = in(pair, r, ==) + isin = in(pair, r) if ismissing(isin) anymissing = true elseif !isin diff --git a/base/dict.jl b/base/dict.jl index 872c9ca0e3188f..d2f6c619ba4741 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -756,7 +756,7 @@ end function haskey(dict::ImmutableDict, key) while isdefined(dict, :parent) - dict.key == key && return true + isequal(dict.key, key) && return true dict = dict.parent end return false @@ -764,14 +764,14 @@ end function getindex(dict::ImmutableDict, key) while isdefined(dict, :parent) - dict.key == key && return dict.value + isequal(dict.key, key) && return dict.value dict = dict.parent end throw(KeyError(key)) end function get(dict::ImmutableDict, key, default) while isdefined(dict, :parent) - dict.key == key && return dict.value + isequal(dict.key, key) && return dict.value dict = dict.parent end return default diff --git a/test/dict.jl b/test/dict.jl index eaf258a1f04a24..3c1121c118c381 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -277,6 +277,8 @@ end @test ismissing(Dict(1=>missing) == Dict(1=>missing)) @test isequal(Dict(1=>missing), Dict(1=>missing)) + d = Dict(1=>missing) + @test ismissing(d == d) @test Dict(missing=>1) == Dict(missing=>1) @test isequal(Dict(missing=>1), Dict(missing=>1)) @@ -716,6 +718,8 @@ import Base.ImmutableDict d5 = ImmutableDict(v...) @test d5 == d2 @test collect(d5) == v + + @test !haskey(ImmutableDict(-0.0=>1), 0.0) end @testset "filtering" begin