E1009: fix_it
E1009 fix_it — a near-miss the parser knows the correction for.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E1009).
The rule
E1009 covers near-misses for which the parser knows the exact correction, and the message states it. Here a require has no else Tag: Soma needs the tag because it becomes the error kind the caller sees when the condition is false. Add else and a tag name, for example require amount <= current else InsufficientFunds.
A program that triggers it
wrong.cell
cell Wallet {
memory {
balances: Map<String, Int> [persistent]
}
on withdraw(owner: String, amount: Int) {
let current = balances.get(owner) ?? 0
require amount <= current
balances.set(owner, current - amount)
return current - amount
}
}What soma check prints:
$ soma check wrong.cell
error: `require` needs `else Tag` — `require len(rows) < 500 else Full` (the tag is the error kind a caller sees)
--> wrong.cell:8:9
|
8 | balances.set(owner, current - amount)
| ^
= code: E1009The fix
On line 7, require amount <= current becomes require amount <= current else InsufficientFunds.
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -5,5 +5,5 @@
on withdraw(owner: String, amount: Int) {
let current = balances.get(owner) ?? 0
- require amount <= current
+ require amount <= current else InsufficientFunds
balances.set(owner, current - amount)
return current - amountWith the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.