V2040 unused_value
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:
List.push(xs, 1)Fixed:
xs = List.push(xs, 1) // or: let _ = …Wrong program
compiler/tests/ui/V2040_unused_value.sakura, which the compiler's ui suite runs through sakura check:
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):
{
"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
compiler/tests/ui/V2040_unused_value.fixed.sakura, which sakura check accepts with no diagnostics:
fn grow() -> List<Int> {
var xs = [1]
xs = List.push(xs, 2)
xs
}