# XO0410: reading a Map by index; use `get` or `get_or_fault`

A missing key is the Map form of a nil dereference, so `m[k]` in an expression, or an in place change through it (`m[k].f = v`, `m[k] += 1`), is an error. Use `m.get(k)` (an optional), `m.get_or_fault(k, "why the key must exist")`, or `m.update(k, init, fn(var v) { ... })`. On a `var` map the whole value assignment `m[k] = v` is allowed and means `m.put(k, v)`. See core 3.6.

## Example

```xo
fn f(m: Map[Str, Int]) -> Int {
  m["a"]
}
```

## Fix

```xo
fn f(m: Map[Str, Int]) -> Int {
  m.get("a") ?? 0
}
```

Run `xo explain XO0410` for this text in a terminal, or see
[section 10.6 of the specification](../../spec/core/#106-diagnostic-codes).

