-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
The document says accessing an index out of bound result in panic
Indexing [], .: array, dict, string, error only. Attempts to access an index out of bounds will result in a panic. Additionally, dicts and errors may be indexed with the dot . operator, as long as the key is a valid identifier.
So I understand following two cases will fail
# case 1
let arr = []
std.print(arr[0]) # panic, index (0) out of bounds# case 2
let dict = @[]
std.print(dict["a"]) # panic, index ("a") out of boundsHowever, if I put the indexing operator on the left hand side, the behavior seems to be inconsistent
# case 3
let arr = []
arr[0] = 1 # panic, index (0) out of bounds
std.print(arr[0])# case 4
let dict = @[]
dict["a"] = 1 # no panic here, a new key-value pair is inserted
std.print(dict["a"])It feels like case 4 does not follow the documentation.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels