E0055: test_helper_shadows
E0055 test_helper_shadows — a test helper named like a program handler or a builtin.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0055).
The rule
A handler defined inside a cell test has the name of a program handler or of a builtin, so the test's calls would run the helper instead of the code or builtin it means to use. Soma refuses this because the assertions would then test the wrong thing. Rename the helper, conventionally with a leading underscore (_entries).
A program that triggers it
wrong.cell
cell Ledger {
on balance(movements: List<Int>) {
return sum(movements)
}
}
cell test LedgerTests {
on entries() {
return [10000, -4000, 2500]
}
rules {
assert balance(entries()) == 8500
}
}What soma check prints:
$ soma check wrong.cell
error: test helper `entries` has the name of the builtin `entries` — it would replace it in this test; rename it (`_entries`)
--> wrong.cell:8:5
|
8 | on entries() {
| ^
= code: E0055
✗ 1 error(s), 0 warning(s).The fix field of soma check --json: it would replace it in this test; rename it (`_entries`)
The fix
On line 8, on entries() { becomes on _entries() {; on line 12, assert balance(entries()) == 8500 becomes assert balance(_entries()) == 8500.
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -6,9 +6,9 @@
cell test LedgerTests {
- on entries() {
+ on _entries() {
return [10000, -4000, 2500]
}
rules {
- assert balance(entries()) == 8500
+ assert balance(_entries()) == 8500
}
}With the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.