Skip to content
Playground(another site)

bynk.val.needs_pin

Error A bare Val[T] cannot generate a value (e.g. a Matches string); pin one.

In a test, a bare Val[T] fabricates a valid value of T. It can do that for most refinements (Positive gives 1, MinLength(3) a string of length three) but not for a Matches pattern or IsoDate, so it refuses rather than guess; the same goes for a record or sum that reaches one. A for all over such a type is refused too. Pin a value, Val[Code]("abc"), which is checked against the refinement, or give the type an @example and use bare Val. See the bynk.val.* codes for pins that are not literals or do not satisfy the type.

Example

demo/codes.bynk
type Code = String where Matches("[a-z]+")
// tests/codes.test.bynk
let c = Val[Code] // ✗ no value can be made from a pattern
let c = Val[Code]("abc") // ✓ pin one

In the Book

See also