E0067: rules_outside_test
E0067 rules_outside_test — a rules block outside a cell test.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0067).
The rule
Test rules (assert, property) belong inside a cell test with a rules block; a rules block in an ordinary cell is refused because those rules would never run. Move them to their own test cell, cell test CartTests { rules { ... } }, which can call the program's handlers unqualified.
A program that triggers it
wrong.cell
cell Cart {
memory {
items: Map<String, Int> [persistent]
}
on add(sku: String, qty: Int) {
items.set(sku, (items.get(sku) ?? 0) + qty)
return items.get(sku)
}
rules {
assert add("apple", 2) == 2
}
}What soma check prints:
$ soma check wrong.cell
error: cell 'Cart' has 1 test rule(s) (assert / property) but is not a test cell — they would never run: move them to `cell test CartTests { rules { … } }`
--> wrong.cell:9:5
|
9 | rules {
| ^
= code: E0067
✗ 1 error(s), 0 warning(s).The fix field of soma check --json: they would never run: move them to `cell test CartTests { rules { … } }`
The fix
3 lines are added after line 8.
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -7,4 +7,7 @@
return items.get(sku)
}
+}
+
+cell test CartTests {
rules {
assert add("apple", 2) == 2With the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.