Skip to content
Playground(another site)

bynk.val.outside_test

Error Val[T] was used outside a test case body.

Val[T] fabricates a value that merely satisfies T. That is what a test wants and what running code must not do, so Val is allowed only in test code. In a function or handler, take the value as a parameter or build it properly, for instance with Age.of(20). See bynk.val.needs_pin for a bare Val that a test cannot generate.

Example

demo/ages.bynk
type Age = Int where InRange(0, 150)
fn sample() -> Age { Val[Age] } // ✗ not test code
// tests/ages.test.bynk
let a = Val[Age] // ✓ in a case

In the Book

See also

  • The grammar rule it governs: val_expr.
  • Every code in its category, Value fabrication, on the diagnostic index.
  • bynk explain bynk.val.outside_test shows the same from the installed toolchain, without a network.