Skip to content

Commit ec2fd64

Browse files
authored
Merge pull request #14 from jw3126/pr
fix hash of negative enums
2 parents 808d528 + 526266d commit ec2fd64

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StructHelpers"
22
uuid = "4093c41a-2008-41fd-82b8-e3f9d02b504f"
33
authors = ["Jan Weidner <[email protected]> and contributors"]
4-
version = "1.3.0"
4+
version = "1.3.1"
55

66
[deps]
77
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"

src/StructHelpers.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ macro enumbatteries(T, kw...)
461461
if nt.hash
462462
def = :(function Base.hash(o::$T, h::UInt)
463463
h = ($start_hash)(o, h, $(nt.typesalt))
464-
Base.hash(UInt(o), h)
464+
Base.hash(Integer(o), h)
465465
end
466466
)
467467
push!(ret.args, def)

test/runtests.jl

+8
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ end
174174
@test_throws Exception convert(Shape, "Circle")
175175
end
176176

177+
@enum Negative MinusOne=-1 MinusTwo=-2 MinusThree=-3
178+
@enumbatteries Negative typesalt = 0xd11b6121f2b8cd22
179+
177180
@testset "@enumbatteries hash" begin
178181
# hash with typesalt
179182
@test hash(Circle) == hash(7, hash(0x0578044908fb9846))
@@ -186,6 +189,11 @@ end
186189

187190
# no hash by default
188191
@test hash(Red) != hash(0, hash(Color))
192+
193+
h = 0xed315b93bf264f3e
194+
typesalt = 0xd11b6121f2b8cd22
195+
@test hash(MinusOne, h) == hash(-1, hash(typesalt, h))
196+
@test hash(MinusTwo, h) == hash(-2, hash(typesalt, h))
189197
end
190198

191199
struct Bad end

0 commit comments

Comments
 (0)