Skip to content
Playground(another site)

bynk.parse.invariant_after_handler

Error An invariant was declared after a handler; invariants precede handlers.

An agent's declarations come in phases: store fields, then invariants, then on handlers. An invariant after a handler is refused, so that every property the handlers must preserve sits together above them. Move the invariant above the first handler.

Example

agent Tally {
key id: String
store count: Cell[Int]
on call get() -> Effect[Result[Int, String]] {
Ok(count)
}
invariant nonNegative: count >= 0 // ✗ after a handler
}
agent Tally {
key id: String
store count: Cell[Int]
invariant nonNegative: count >= 0 // ✓ before the handlers
on call get() -> Effect[Result[Int, String]] {
Ok(count)
}
}

In the Book

See also

  • Every code in its category, Parser, on the diagnostic index.
  • bynk explain bynk.parse.invariant_after_handler shows the same from the installed toolchain, without a network.