soma.cell

W0011: dispatch_shadow

W0011 dispatch_shadow — a bare call that two definitions could answer.

A warning of soma check, the checker of the Soma programming language (soma explain W0011).

The rule

When two cells define a handler with the same name, a bare call to that name inside one of them runs that cell's own handler, and soma check warns with W0011 because the other one might have been meant. From a third cell the same bare call is an error, since neither is preferred. Qualify the call with the cell name (Orders.pack(order_id) or Warehouse.pack(order_id)) to say which handler runs.

A program that triggers it

wrong.cell

cell Orders {
    on pack(order_id: String) {
        return "order {order_id} ready"
    }
}

cell Warehouse {
    on pack(order_id: String) {
        return "box for {order_id}"
    }
    on ship(order_id: String) {
        let label = pack(order_id)
        return "shipping: {label}"
    }
}

What soma check prints:

$ soma check wrong.cell
warning: call to 'pack' inside Warehouse.ship: both Warehouse and Orders define 'pack' — the bare call runs Warehouse's own; write Orders.pack(...) if you meant Orders's
  --> wrong.cell:12:21
   |
12 |         let label = pack(order_id)
   |                     ^
✓ 1 warning(s), no errors.

The fix field of soma check --json: Rename one of the colliding handlers so the bare-name call is unambiguous.

On line 12, let label = pack(order_id) becomes let label = Orders.pack(order_id).

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -10,5 +10,5 @@
     }
     on ship(order_id: String) {
-        let label = pack(order_id)
+        let label = Orders.pack(order_id)
         return "shipping: {label}"
     }

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.