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

Fix hash(::AbstractArray) failure in when some types support - and others do not #25250

Merged
merged 1 commit into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,7 @@ function hash(a::AbstractArray{T}, h::UInt) where T
# If true, wraparound overflow happened
sign(step) == cmp(x2, x1) || break
else
applicable(-, x2, x1) || break
# widen() is here to ensure no overflow can happen
step = widen(x2) - widen(x1)
end
Expand Down
1 change: 1 addition & 0 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ julia> widen(1.5f0)
```
"""
widen(x::T) where {T} = convert(widen(T), x)
widen(x::Type{T}) where {T} = throw(MethodError(widen, (T,)))

# function pipelining

Expand Down
2 changes: 2 additions & 0 deletions test/hashing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ vals = Any[
Any[Int8(127), Int8(-128), -383], 127:-255:-383,
# Loss of precision with Float64
Any[-2^53-1, 0.0, 2^53+1], [-2^53-1, 0, 2^53+1], (-2^53-1):2^53+1:(2^53+1),
# Some combinations of elements support -, others do not
[1, 2, "a"], [1, "a", 2], [1, 2, "a", 2], [1, 'a', 2],
Set([1,2,3,4]),
Set([1:10;]), # these lead to different key orders
Set([7,9,4,10,2,3,5,8,6,1]), #
Expand Down
3 changes: 3 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2400,6 +2400,9 @@ end
@test typeof(widemul(UInt64(1),Int64(1))) == Int128
@test typeof(widemul(Int128(1),UInt128(1))) == BigInt
@test typeof(widemul(UInt128(1),Int128(1))) == BigInt

# Check that the widen() fallback doesn't trigger a StackOverflowError
@test_throws MethodError widen(String)
end
@testset ".//" begin
@test [1,2,3] // 4 == [1//4, 2//4, 3//4]
Expand Down