Skip to content

Array hashing breaks equality on 0.7 #26034

Closed
@chethega

Description

@chethega
struct totally_not_five end

Base.isequal(::totally_not_five, x)=isequal(5,x);
Base.isequal(x, ::totally_not_five)=isequal(5,x);
Base.isequal(::totally_not_five, ::totally_not_five)=true;
Base.hash(::totally_not_five, h::UInt64)=hash(5, h);
import Base.==
==(::totally_not_five, x)= (5==x);
==(x,::totally_not_five)= (5==x);
==(::totally_not_five,::totally_not_five)=true;

n5=totally_not_five();

############
versioninfo()
#Julia Version 0.7.0-DEV.3961
#Commit 12964e839e* (2018-02-13 10:42 UTC)

5== n5 #true
isequal([4,n5,6], [4,5,6]) #true 
isequal(hash([4,n5,6]), hash([4,5,6])) # false
isequal(hash([n5,4,n5,6]), hash([n5,4,5,6])) #true 

############ 
versioninfo()
#Julia Version 0.6.2
#Commit d386e40 (2017-12-13 18:08 UTC)

5== n5 #true
isequal([4,n5,6], [4,5,6]) #true 
isequal(hash([4,n5,6]), hash([4,5,6])) # true
isequal(hash([n5,4,n5,6]), hash([n5,4,5,6])) #true 

I fear that this is fundamental to the current approach for O(1) range hashing (but I would be happy to be corrected!).

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]hashingregressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions