Open
Description
Since we added support for optional fields on records, a crucial assumption was broken: up until then, records can be expected to have a fixed layout, as its definition.
So records with the same values for the same keys always had the same hash.
However, by introducing optional fields, we can easily create values that pass the equality check but have different hashes.
type t = {
a: string,
b?: string,
c: string,
}
let v1 = {
a: "a",
c: "c",
}
let v2 = {
...v1,
b: "b",
}
let v3 = {
a: "a",
b: "b",
c: "c"
}
assert (Hashtbl.hash(v2) == Hashtbl.hash(v3))
v2
and v3
have the same values for the same keys but in different order.
Obj.entries(v2)
=>[['a', 'a'], ['c', 'c'], ['b', 'b']]
Obj.entries(v3)
=>[['a', 'a'], ['b', 'b'], ['c', 'c']]
This literally means that users can't use a record as a key in a hashtable or other data structure. In other words, it's not a record.
Metadata
Metadata
Assignees
Labels
No labels