-
Notifications
You must be signed in to change notification settings - Fork 477
Closed as not planned
Labels
staleOld issues that went staleOld issues that went stale
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.
mununkiXiNiHa and tsnobip
Metadata
Metadata
Assignees
Labels
staleOld issues that went staleOld issues that went stale