soma.cell

E0111: maybe_absent

E0111 maybe_absent — a value that may be absent () used where a value is required.

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

The rule

In edition 2027 (edition = "2027" in soma.toml), soma check tracks values that may be absent, such as stock.get(sku) on a Map slot, which is () for a key never written, and reports E0111 when one is used where a value is required, as an operand of + here. In edition 2026 the same program passes check and () + qty fails only when it runs on a new key. Give the absent case a value with (stock.get(sku) ?? 0), or test it first with require stock.get(sku) != () else Missing.

A program that triggers it

soma.toml

[package]
name = "inventory"
edition = "2027"

wrong.cell

cell Inventory {
    face {
        signal restock(sku: String, qty: Int) -> Int
    }
    memory {
        stock: Map<String, Int> [persistent]
    }
    on restock(sku: String, qty: Int) {
        let n = stock.get(sku) + qty
        stock.set(sku, n)
        return n
    }
}

What soma check prints:

$ soma check wrong.cell
error: `stock.get(sku)` may be absent (`()`) in `+` — default it (`(stock.get(sku) ?? 0)`) or test it first (`require stock.get(sku) != () else Missing`)
  --> wrong.cell:9:17
  |
9 |         let n = stock.get(sku) + qty
  |                 ^
  = code: E0111
✗ 1 error(s), 0 warning(s).

The fix field of soma check --json: default it (`(stock.get(sku) ?? 0)`) or test it first (`require stock.get(sku) != () else Missing`)

On line 9, let n = stock.get(sku) + qty becomes let n = (stock.get(sku) ?? 0) + qty.

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -7,5 +7,5 @@
     }
     on restock(sku: String, qty: Int) {
-        let n = stock.get(sku) + qty
+        let n = (stock.get(sku) ?? 0) + qty
         stock.set(sku, n)
         return n

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.