soma.cell

E0041: arity

E0041 arity — a call with the wrong number of arguments.

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

The rule

A qualified call Cell.handler(…) passes a number of arguments that the handler does not accept. Soma checks the count at compile time instead of letting the call fail when it runs. Pass every parameter the handler declares (a trailing Map parameter may be left out). The same mistake written as a bare call (post(x)) is reported as E0012.

A program that triggers it

wrong.cell

cell Ledger {
    memory {
        entries: Map<String, Int> [persistent]
    }
    on post(order_id: String, cents: Int) {
        entries.set(order_id, cents)
        return cents
    }
}

cell Checkout {
    on pay(order_id: String, cents: Int) {
        require cents > 0 else InvalidAmount
        return Ledger.post(order_id)
    }
}

What soma check prints:

$ soma check wrong.cell
error: `Ledger.post(…)` passes 1 argument(s), but the handler Ledger.post takes 2
  --> wrong.cell:14:16
   |
14 |         return Ledger.post(order_id)
   |                ^
  = code: E0041
✗ 1 error(s), 0 warning(s).

The fix field of soma check --json: `Ledger.post(…)` passes 1 argument(s), but the handler Ledger.post takes 2

On line 14, return Ledger.post(order_id) becomes return Ledger.post(order_id, cents).

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -12,5 +12,5 @@
     on pay(order_id: String, cents: Int) {
         require cents > 0 else InvalidAmount
-        return Ledger.post(order_id)
+        return Ledger.post(order_id, cents)
     }
 }

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.