Skip to content
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StructHelpers"
uuid = "4093c41a-2008-41fd-82b8-e3f9d02b504f"
authors = ["Jan Weidner <jw3126@gmail.com> and contributors"]
version = "1.3.0"
version = "1.3.1"

[deps]
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Expand Down
2 changes: 1 addition & 1 deletion src/StructHelpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ macro enumbatteries(T, kw...)
if nt.hash
def = :(function Base.hash(o::$T, h::UInt)
h = ($start_hash)(o, h, $(nt.typesalt))
Base.hash(UInt(o), h)
Base.hash(Integer(o), h)
end
)
push!(ret.args, def)
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ end
@test_throws Exception convert(Shape, "Circle")
end

@enum Negative MinusOne=-1 MinusTwo=-2 MinusThree=-3
@enumbatteries Negative typesalt = 0xd11b6121f2b8cd22

@testset "@enumbatteries hash" begin
# hash with typesalt
@test hash(Circle) == hash(7, hash(0x0578044908fb9846))
Expand All @@ -186,6 +189,11 @@ end

# no hash by default
@test hash(Red) != hash(0, hash(Color))

h = 0xed315b93bf264f3e
typesalt = 0xd11b6121f2b8cd22
@test hash(MinusOne, h) == hash(-1, hash(typesalt, h))
@test hash(MinusTwo, h) == hash(-2, hash(typesalt, h))
end

struct Bad end
Expand Down
Loading