E1008: statement_as_value
E1008 statement_as_value — a statement where a value is expected.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E1008).
The rule
A statement keyword such as return, let, require, for or while cannot stand where a value is expected: in a lambda body, as an operand or as an argument. A lambda's value is its expression, so id => return x is refused. Drop the return (id => (totals.get(id) ?? 0) >= min_total), or use a block lambda whose last expression is the value.
A program that triggers it
wrong.cell
cell Orders {
memory {
totals: Map<String, Int> [persistent]
}
on large_orders(min_total: Int) {
let ids = keys(totals)
return filter(ids, id => return (totals.get(id) ?? 0) >= min_total)
}
}What soma check prints:
$ soma check wrong.cell
error: `return` starts a statement and cannot stand where a value is expected (a lambda `x => …`, an operand, an argument) — a lambda's value is its expression: drop the `return` (`x => x + 1`, or `x => { let y = x * 2 y + 1 }`); as a name it is reserved (`return_id`)
--> wrong.cell:7:34
|
7 | return filter(ids, id => return (totals.get(id) ?? 0) >= min_total)
| ^
= code: E1008The fix
On line 7, return filter(ids, id => return (totals.get(id) ?? 0) >= min_total) becomes return filter(ids, id => (totals.get(id) ?? 0) >= min_total).
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -5,5 +5,5 @@
on large_orders(min_total: Int) {
let ids = keys(totals)
- return filter(ids, id => return (totals.get(id) ?? 0) >= min_total)
+ return filter(ids, id => (totals.get(id) ?? 0) >= min_total)
}
}With the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.