soma.cell

E0034: storage_collision

E0034 storage_collision — two slots would share one storage table.

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

The rule

Every memory slot is stored in a table named <Cell>_<slot>, and each slot also uses a second table with _log appended; table names ignore case. A slot stock therefore already owns Inventory_stock_log, so a second slot named stock_log would share it and the two slots would overwrite each other's data. Rename one of the slots; slot names starting with __ are refused for the same reason, since the runtime keeps state machine instances under __sm_….

A program that triggers it

wrong.cell

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

What soma check prints:

$ soma check wrong.cell
error: slot Inventory.stock and slot Inventory.stock_log would share the storage table "Inventory_stock_log" (table names ignore case and `_` joins cell and slot names) — rename one of them
  --> wrong.cell:1:1
  |
1 | cell Inventory {
  | ^
  = code: E0034
✗ 1 error(s), 0 warning(s).

The fix field of soma check --json: rename one of them

On line 7, stock_log: List<String> [persistent] becomes restock_history: List<String> [persistent]; on line 12, stock_log.push("{sku} +{qty}") becomes restock_history.push("{sku} +{qty}").

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -5,10 +5,10 @@
     memory {
         stock: Map<String, Int> [persistent]
-        stock_log: List<String> [persistent]
+        restock_history: List<String> [persistent]
     }
     on restock(sku: String, qty: Int) {
         let level = (stock.get(sku) ?? 0) + qty
         stock.set(sku, level)
-        stock_log.push("{sku} +{qty}")
+        restock_history.push("{sku} +{qty}")
         return level
     }

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.