E0007: duplicate_signal
E0007 duplicate_signal — two handlers of one cell share a name.
A compile-time error of soma check, the checker of the Soma programming language (soma explain E0007).
The rule
A cell may not have two on handlers with the same name, even when their parameters are identical; Soma does not overload handlers. A call balance(owner) must resolve to exactly one body. Give the second handler its own name (here balance_in_units), or merge the two bodies into one.
A program that triggers it
wrong.cell
cell Wallet {
memory {
balances: Map<String, Int> [persistent]
}
on balance(owner: String) {
return balances.get(owner) ?? 0
}
on balance(owner: String) {
return (balances.get(owner) ?? 0) / 100
}
}What soma check prints:
$ soma check wrong.cell
error: duplicate signal 'balance' in cell 'Wallet'
--> wrong.cell:8:5
|
8 | on balance(owner: String) {
| ^
= code: E0007
✗ 1 error(s), 0 warning(s).The fix field of soma check --json: Remove the duplicate handler 'on balance()' in cell 'Wallet'.
The fix
On line 8, on balance(owner: String) { becomes on balance_in_units(owner: String) {.
wrong.cell → right.cell
--- wrong.cell
+++ right.cell
@@ -6,5 +6,5 @@
return balances.get(owner) ?? 0
}
- on balance(owner: String) {
+ on balance_in_units(owner: String) {
return (balances.get(owner) ?? 0) / 100
}With the fix, soma check accepts the program:
$ soma check right.cell
✓ All checks passed.