Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash does not include type name #9

Open
bradleyjkemp opened this issue Oct 5, 2017 · 1 comment
Open

Hash does not include type name #9

bradleyjkemp opened this issue Oct 5, 2017 · 1 comment
Assignees

Comments

@bradleyjkemp
Copy link

Currently the hash only includes the fields of a struct and not the name of the struct type. This causes potentially unwanted hash collisions as seen below:

type TypeA struct {
        Foo string
        Bar string
}

type TypeB struct {
        Foo string
        Bar string
}

func TestTags(t *testing.T) {
        t1 := TypeA{"foo", "bar"}
        t2 := TypeB{"foo", "bar"}
        h1, err := Hash(t1, 1)
        if err != nil {
                panic(err)
        }
        h2, err := Hash(t2, 1)
        if err != nil {
                panic(err)
        }
        if h1 == h2 {
                t.Error("hash collision")
        }
}
@cnf cnf self-assigned this Oct 9, 2017
@cnf cnf added the enhancement label Oct 9, 2017
@cnf
Copy link
Owner

cnf commented Oct 9, 2017

Thanks for the report. I don't think i'll change the current behaviour, but I might add some extra calls to give you the ability to differentiate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants