soma.cell

W0019: frame_warning

W0019 frame_warning — a skeleton that says more than the program does: a frame wider than its body, a machine edge or a slot no frame touches, a helper nothing calls.

A warning of soma check, the checker of the Soma programming language (soma explain W0019).

The rule

A skeleton's frames say what each signal's body may do, and soma check warns with W0019 when the skeleton says more than the program does: a frame wider than its body, a machine edge or a slot no frame touches, or a helper nothing calls. Here level is granted writes stock but its body only reads the slot, so the frame overstates what the signal can change. Narrow the frame to what the body does: reads stock.

A program that triggers it

wrong.cell

skeleton Inventory {
    memory {
        stock: Map<String, Int> [persistent]
        invariant stock >= 0
    }
    face {
        signal level(sku: String) -> Int                writes stock
        signal restock(sku: String, qty: Int) -> Int    writes stock
    }
}

flesh Inventory {
    on level(sku) { return stock.get(sku) ?? 0 }
    on restock(sku, qty) {
        let next = (stock.get(sku) ?? 0) + qty
        stock.set(sku, next)
        return next
    }
}

What soma check prints:

$ soma check wrong.cell
warning: `Inventory.level`: the frame says `writes stock`, the body only reads it — declare `reads stock`
  --> wrong.cell:7:9
  |
7 |         signal level(sku: String) -> Int                writes stock
  |         ^
✓ 1 warning(s), no errors.

The fix field of soma check --json: Review and address the reported warning.

On line 7, signal level(sku: String) -> Int writes stock becomes signal level(sku: String) -> Int reads stock.

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -5,5 +5,5 @@
     }
     face {
-        signal level(sku: String) -> Int                writes stock
+        signal level(sku: String) -> Int                reads stock
         signal restock(sku: String, qty: Int) -> Int    writes stock
     }

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.