E0045: unused_value
E0045 unused_value — an expression statement whose value is dropped.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0045).
The rule
An expression that stands alone on its own line, and is not the last statement of its block, is computed and thrown away. This usually means a missing operator: a newline ends a statement, so let total = a + b followed by tax on the next line is two statements. Put the operator at the end of the first line (a + b +) so the expression continues, or bind or use the value.
A program that triggers it
wrong.cell
cell Invoice {
face {
signal total(subtotal_cents: Int, shipping_cents: Int, tax_cents: Int) -> Int
}
on total(subtotal_cents: Int, shipping_cents: Int, tax_cents: Int) {
let total = subtotal_cents + shipping_cents
tax_cents
return total
}
}What soma check prints:
$ soma check wrong.cell
error: `tax_cents` on its own does nothing — a value that is not the last statement of its block is thrown away (a missing operator between two values? `let x = a b` is two statements)
--> wrong.cell:7:13
|
7 | tax_cents
| ^
= code: E0045
✗ 1 error(s), 0 warning(s).The fix field of soma check --json: a value that is not the last statement of its block is thrown away (a missing operator between two values? `let x = a b` is two statements)
The fix
On line 6, let total = subtotal_cents + shipping_cents becomes let total = subtotal_cents + shipping_cents +.
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -4,5 +4,5 @@
}
on total(subtotal_cents: Int, shipping_cents: Int, tax_cents: Int) {
- let total = subtotal_cents + shipping_cents
+ let total = subtotal_cents + shipping_cents +
tax_cents
return totalWith the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.