# V2040 unused_value

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

> A non-final expression statement produces a non-Unit value that is dropped.

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

A non-final expression statement produces a non-`Unit` value that is dropped. This catches
forgotten reassignments such as `List.push(xs, 1)` (design §8.1).

Wrong:

```sakura
List.push(xs, 1)
```

Fixed:

```sakura
xs = List.push(xs, 1)      // or: let _ = …
```

## Wrong program [#wrong-program]

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

```sakura
fn grow() -> List<Int> {
  var xs = [1]
  List.push(xs, 2)
  xs
}
```

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

```json
{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:97bb246911dad89c",
  "code": "V2040",
  "severity": "error",
  "phase": "type",
  "message": "this expression produces a `List<Int>` that is never used",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V2040_unused_value::grow",
  "spans": [
    {
      "uri": "file://$DIR/V2040_unused_value.sakura",
      "content_hash": "sha256:7b646d34a2de853d303274a74c43956873368e72ede612763bde2b4f04167b85",
      "start_byte": 76,
      "end_byte": 92,
      "role": "primary",
      "label": "`List<Int>` value dropped here"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": {
    "render": "List<Int>"
  },
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V2040",
  "fixes": [
    {
      "id": "f:97bb246911dad89c.0",
      "title": "Discard the value explicitly with `let _ =`",
      "applicability": "suggested",
      "impact": "local",
      "edits": [
        {
          "span": {
            "uri": "file://$DIR/V2040_unused_value.sakura",
            "content_hash": "sha256:7b646d34a2de853d303274a74c43956873368e72ede612763bde2b4f04167b85",
            "start_byte": 76,
            "end_byte": 76,
            "role": "primary"
          },
          "replacement": "let _ = "
        }
      ]
    }
  ]
}
```

## Fixed program [#fixed-program]

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

```sakura
fn grow() -> List<Int> {
  var xs = [1]
  xs = List.push(xs, 2)
  xs
}
```
