# V2010 cannot_infer_type

URL: /docs/errors/V2010
Markdown: /docs/errors/V2010.md

> The type of an empty collection literal (or another binding) cannot be inferred from its uses.

An error from the `type` phase. `sakura explain V2010` prints this explanation offline.

The type of an empty collection literal (or another binding) cannot be inferred from its uses.

Wrong:

```sakura
let xs = []
```

Fixed:

```sakura
let xs: List<Int> = []
```

## Wrong program [#wrong-program]

[`compiler/tests/ui/V2010_cannot_infer_type.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/V2010_cannot_infer_type.sakura), which the compiler's ui suite runs through `sakura check`:

```sakura
fn nothing() -> Unit { var xs = [] }
```

`sakura check --json` reports this record (pretty-printed; `$DIR` is the fixture's directory):

```json
{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:7bd606d3e6bdb2f2",
  "code": "V2010",
  "severity": "error",
  "phase": "type",
  "message": "cannot infer the element type of this empty list; annotate the binding, e.g. `let xs: List<Int> = []`",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V2010_cannot_infer_type::nothing",
  "spans": [
    {
      "uri": "file://$DIR/V2010_cannot_infer_type.sakura",
      "content_hash": "sha256:7b2a782e8ea86858f4650be47c08d6121626c4ac6afdf02c4dfe137ee29a0cd8",
      "start_byte": 66,
      "end_byte": 68,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V2010",
  "fixes": []
}
```

## Fixed program [#fixed-program]

[`compiler/tests/ui/V2010_cannot_infer_type.fixed.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/V2010_cannot_infer_type.fixed.sakura), which `sakura check` accepts with no diagnostics:

```sakura
fn nothing() -> List<Int> {
  var xs: List<Int> = []
  xs
}
```
