soma.cell

E0083: invariant_not_bool

E0083 invariant_not_bool — an invariant that is not a condition.

A compile-time error of soma check, the checker of the Soma programming language (soma explain E0083).

The rule

A memory invariant must be a condition. A bare slot name or an arithmetic expression such as invariant balances is refused, because it would be judged by truthiness rather than by a comparison. Compare it: invariant balances >= 0 (on a Map slot it applies to every value written).

A program that triggers it

wrong.cell

cell Account {
    memory {
        balances: Map<String, Int> [persistent]
        invariant balances
    }
    on deposit(id: String, amount: Int) {
        balances.set(id, (balances.get(id) ?? 0) + amount)
    }
}

What soma check prints:

$ soma check wrong.cell
error: invariant `balances` is not a condition — compare it (`balances >= 0`, `size <= 100`)
  --> wrong.cell:4:9
  |
4 |         invariant balances
  |         ^
  = code: E0083
✗ 1 error(s), 0 warning(s).

The fix field of soma check --json: compare it (`balances >= 0`, `size <= 100`)

On line 4, invariant balances becomes invariant balances >= 0.

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -2,5 +2,5 @@
     memory {
         balances: Map<String, Int> [persistent]
-        invariant balances
+        invariant balances >= 0
     }
     on deposit(id: String, amount: Int) {

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.