Fix hashing related bug. Fixes JuliaLang/julia#6859 and #49.