E0078: multiple_state_machines
E0078 multiple_state_machines — more than one state machine in a cell.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0078).
The rule
A cell has one lifecycle, so it may declare only one state machine; a second one is refused. In this binary the second machine's states are also not known to transition() in that cell, which is why check additionally reports "shipped" as an undeclared state. Put the second machine in its own cell.
A program that triggers it
wrong.cell
cell Order {
state payment {
initial: unpaid
unpaid -> paid
}
state shipping {
initial: waiting
waiting -> shipped
}
on pay(id: String) { transition(id, "paid") }
on ship(id: String) { transition(id, "shipped") }
}What soma check prints:
$ soma check wrong.cell
error: cell 'Order' declares 2 state machines — a cell has one lifecycle; put the second machine in its own cell
--> wrong.cell:6:5
|
6 | state shipping {
| ^
= code: E0078
error: transition() to "shipped" in handler 'ship' — no such state in `state { }` of cell 'Order': declare the edge or fix the name
--> wrong.cell:11:27
|
11 | on ship(id: String) { transition(id, "shipped") }
| ^
= code: E0027
✗ 2 error(s), 0 warning(s).The fix field of soma check --json: a cell has one lifecycle; put the second machine in its own cell
The fix
4 lines are added after line 5; line 10 is removed.
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -4,9 +4,12 @@
unpaid -> paid
}
+ on pay(id: String) { transition(id, "paid") }
+}
+
+cell Shipping {
state shipping {
initial: waiting
waiting -> shipped
}
- on pay(id: String) { transition(id, "paid") }
on ship(id: String) { transition(id, "shipped") }
}With the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.