Home / Docs / Diagnostics

U3010: Handler does not match its capability

Release v0.4.0

A handler implements the capability it names after for, with one implementation per operation, named as the capability names it and with the same number of parameters (spec/05 §5). A handler installed with with @x = h(args) or given @x = h(args) implements the capability that the statement or the do line needs at @x, and the name installed is a handler (spec/05 §4, spec/02 §8). U3010 reports a for that names something other than a capability, an operation that the capability lacks or with another parameter count, and an installation of something other than a matching handler.

The repair at a glance

diff
  module demo

  capability Log
    op write(line: Text) -> Unit

- capability Audit
-   op record(line: Text) -> Unit
-
- handler silent() for Audit
-   op record(line) = unit
+ handler silent() for Log
+   op write(line) = unit

  pub note(line: Text) -> Unit
    uses @log: Log[write]
  =
    @log.write(line)

  pub report() -> Unit
  =
    note("done") with @log = silent()

Failing example

una
module demo

capability Log
  op write(line: Text) -> Unit

capability Audit
  op record(line: Text) -> Unit

handler silent() for Audit
  op record(line) = unit

pub note(line: Text) -> Unit
  uses @log: Log[write]
=
  @log.write(line)

pub report() -> Unit
=
  note("done") with @log = silent()

Fixed example

una
module demo

capability Log
  op write(line: Text) -> Unit

handler silent() for Log
  op write(line) = unit

pub note(line: Text) -> Unit
  uses @log: Log[write]
=
  @log.write(line)

pub report() -> Unit
=
  note("done") with @log = silent()