Open bsdelf opened 2 months ago
I think we should update the documentation, as dict["a"]
on the left-hand side means insertion (for dicts at least). The current behavior is consistent with other languages such as Python and Lua:
(Python)
>>> d = {}
>>> d["a"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'a'
>>> d["a"] = 1
>>>
(Lua; doesn't panic on case 2 but case 4 works as expected)
> d = {}
> d["a"]
nil
> d["a"] = 1
>
The document says accessing an index out of bound result in panic
So I understand following two cases will fail
However, if I put the indexing operator on the left hand side, the behavior seems to be inconsistent
It feels like case 4 does not follow the documentation.