But when I do this, it seems to ignore my custom hash function in certain contexts:
julia> struct Foo
end
julia> Base.hash(::Foo, h::UInt) = error()
The following calls are what I would expect:
julia> hash(Foo())
ERROR:
Stacktrace:
[1] error()
@ Base ./error.jl:44
[2] hash(::Foo, h::UInt64)
@ Main ./REPL[2]:1
julia> hash((Foo(),))
ERROR:
Stacktrace:
[1] error()
@ Base ./error.jl:44
[2] hash(::Foo, h::UInt64)
@ Main ./REPL[2]:1
But this one is not expected:
julia> struct Bar
x::Foo
end
julia> hash(Bar(Foo()))
0xb4bfb67e8815404c
Is there a reason why the default hash on structs does not recursively travel through fields? Does this mean if I implement a custom hashing function for my type, I also need to overload hash for any type that takes it as a property to ensure my hash gets hit?