From e601b011b2c9308c321104f1a3435ea8896c30b8 Mon Sep 17 00:00:00 2001 From: Sukera Date: Wed, 6 Dec 2023 14:29:03 +0100 Subject: [PATCH] Implement hashing for custom `Some` equality --- base/some.jl | 1 + test/some.jl | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/base/some.jl b/base/some.jl index 0f4d32f1fb5370..a91c3cd3bb5c1f 100644 --- a/base/some.jl +++ b/base/some.jl @@ -147,3 +147,4 @@ macro something(args...) end ==(a::Some, b::Some) = a.value == b.value +hash(s::Some, h::UInt) = hash(s.value, hash(Some, h)) diff --git a/test/some.jl b/test/some.jl index 358c6833942753..3c3050584061fa 100644 --- a/test/some.jl +++ b/test/some.jl @@ -56,6 +56,10 @@ # Two Somes forward to their wrapped things @test ==(Some([0x1]), Some([1])) +# hashing implications +@test hash(Some(0x1)) != hash(0x1) +@test hash(Some(0x1)) == hash(Some(1)) + @testset "something" begin @test_throws ArgumentError something() @test something(1) === 1