https://github.com/JuliaLang/julia/issues/12198

On Fri, May 27, 2016 at 3:40 AM, Dario Prandi <[email protected]> wrote:

> Dear all,
>
> while experimenting with the Set collection I am incurring in a very
> strange behavior when I use a custom type. More precisely:
>
> julia> type Test
>            x::Int
>        end
>
> julia> import Base.==
>
> julia> ==(a::Test, b::Test) = a.x == b.x
> == (generic function with 110 methods)
>
> julia> a = Set{Test}()
> Set{Test}()
>
> julia> push!(a, Test(1))
> Set([Test(1)])
>
> julia> push!(a, Test(1))
> Set([Test(1),Test(1)])
>
> This should not happen, since Test(1)==Test(1). Moreover, I get the
> following
>
> julia> Test(1) ∈ a
> true
>
> julia> haskey(a.dict, Test(1))
> false
>
> which is quite strange, since the definition of the ∈ function is
>
> in(x, s::Set) = haskey(s.dict, x)
>
> Finally, I remark that the following works correctly
>
> julia> x = Test(1)
> Test(1)
>
> julia> a = Set{Test}()
> Set{Test}()
>
> julia> push!(a,x)
> Set([Test(1)])
>
> julia> push!(a,x)
> Set([Test(1)])
>
> Someone has any idea of what is happening here? I'm on v0.4.5, but the
> same behavior is reproducible on v0.5.
>
> Thanks,
> Dario
>

Reply via email to