- Incorrect type checking when &[] and [] return optional values.

- Failed to find subscript overloading on optional values.
- Added `&[]` overload to HashMap.
This commit is contained in:
Christoffer Lerno
2025-08-19 00:40:56 +02:00
parent ba55946c9a
commit de09a19a48
5 changed files with 39 additions and 5 deletions

View File

@@ -182,6 +182,24 @@ fn Value*? HashMap.get_ref(&map, Key key)
return NOT_FOUND?;
}
fn Value* HashMap.get_or_create_ref(&map, Key key) @operator(&[])
{
uint hash = rehash(key.hash());
if (map.count)
{
for (Entry *e = map.table[index_for(hash, map.table.len)]; e != null; e = e.next)
{
if (e.hash == hash && equals(key, e.key)) return &e.value;
}
}
map.set(key, {});
for (Entry *e = map.table[index_for(hash, map.table.len)]; e != null; e = e.next)
{
if (e.hash == hash && equals(key, e.key)) return &e.value;
}
unreachable();
}
fn Entry*? HashMap.get_entry(&map, Key key)
{
if (!map.count) return NOT_FOUND?;