soma.cell

E0004: param_mismatch

E0004 param_mismatch — a handler's parameter count differs from its face signal.

A compile-time error of soma check, the checker of the Soma programming language (soma explain E0004).

The rule

A handler must take as many parameters as the face signal it implements: signal deposit(owner: String, amount: Int) needs on deposit(owner: String, amount: Int). Callers are written against the face, so a handler with fewer or more parameters would receive arguments it does not expect. Make the handler's parameter list match the signal (or change the signal if the contract was wrong).

A program that triggers it

wrong.cell

cell Wallet {
    face {
        signal deposit(owner: String, amount: Int) -> Int
    }
    memory {
        balances: Map<String, Int> [persistent]
    }
    on deposit(owner: String) {
        let total = (balances.get(owner) ?? 0) + 100
        balances.set(owner, total)
        return total
    }
}

What soma check prints:

$ soma check wrong.cell
error: face contract: signal 'deposit' in cell 'Wallet' declares 2 params, handler has 1
  --> wrong.cell:3:9
  |
3 |         signal deposit(owner: String, amount: Int) -> Int
  |         ^
  = code: E0004
✗ 1 error(s), 0 warning(s).

The fix field of soma check --json: Change the handler 'on deposit(...)' in cell 'Wallet' to accept 2 parameter(s) (currently has 1).

Lines 8–9 are rewritten.

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -6,6 +6,6 @@
         balances: Map<String, Int> [persistent]
     }
-    on deposit(owner: String) {
-        let total = (balances.get(owner) ?? 0) + 100
+    on deposit(owner: String, amount: Int) {
+        let total = (balances.get(owner) ?? 0) + amount
         balances.set(owner, total)
         return total

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.