Fix hash comparisons and some other implicit narrowing conversions.
Likely fixes issue #8596.