Laythe-lang / Laythe

A gradually typed language originally based on the crafting interpreters series
MIT License
65 stars 4 forks source link

Mutating Resizable element like List as Hash key won't work correctly #153

Open jonnyboyC opened 1 month ago

jonnyboyC commented 1 month ago

Problem

List's are not immutable further more given that we are using a Gc managed resizble array it is expected the the value points directly to the collection. There may be potentially forwarding pointers which makes it so equality must really be down on the allocation pointers.

Our current implementation of Value doesn't take this into account and means a mutation to a List key after it was set may give unexpected behavior.

Example

let a = [1, 2, 3];
let b = { a: 5 };
a.push(4)
// ??? 
b[a]