Hash nil embedded pointers

This commit is contained in:
Emery Hemingway 2023-11-02 13:33:52 +00:00
parent 0c4ef8269f
commit 7187a45f9c
1 changed files with 7 additions and 1 deletions

View File

@ -223,7 +223,7 @@ proc cannonicalize*[E](pr: var Preserve[E]) =
else:
discard
proc hash*(pr: Preserve): Hash =
proc hash*[E](pr: Preserve[E]): Hash =
## Produce a `Hash` of `pr` for use with a `HashSet` or `Table`.
var h = hash(pr.kind.int) !& hash(pr.embedded)
case pr.kind
@ -254,7 +254,13 @@ proc hash*(pr: Preserve): Hash =
for (key, val) in pr.dict.items:
h = h !& hash(key) !& hash(val)
of pkEmbedded:
when E is void:
h = h !& hash(pr.embed)
else:
if pr.embed.isNil:
h = h !& hash(false)
else:
h = h !& hash(pr.embed)
!$h
proc `[]`*(pr: Preserve; i: int): Preserve =