Skip to content
Playground(another site)

bynk.contract.result_in_requires

Error A precondition (requires) references result; the return value is only in scope inside an ensures.

A requires clause is checked on entry, before the function has returned anything, so result is not bound there. Only an ensures can read it. Either state the condition over the parameters, or, if it is a claim about the return value, make it an ensures. A parameter that is itself named result is read as that parameter.

Example

fn inc(x: Int) -> Int
requires small: result < 100 // ✗ nothing has been returned yet
fn inc(x: Int) -> Int
ensures small: result < 100 // ✓ checked on exit

In the Book

See also

  • Every code in its category, Contracts, on the diagnostic index.
  • bynk explain bynk.contract.result_in_requires shows the same from the installed toolchain, without a network.