bynk.refine.literal_violates
Error A literal does not satisfy the refined type's predicate.
A literal written where a refined type is expected is checked at compile time, and this one does not satisfy the type's predicate. A refined type is a base type plus a rule (InRange, NonEmpty, …), and a literal that breaks the rule can never be a valid value, so the compiler rejects it instead of admitting it. Use a value that satisfies the predicate, or loosen the type. A value known only at run time goes through .of, which returns a Result.
Example
type Age = Int where InRange(0, 150)
fn limit() -> Age { 200 } // ✗ 200 is outside InRange(0, 150)fn limit() -> Age { 150 } // ✓ admitted at compile timeIn the Book
- Refined-type API › Literal admission
- Define a refined type and validate untrusted input
- Use a literal where a refined type is expected
- Refined-type API
- Testing › @example — a value for a pattern
- Testing
- Write tests, stub collaborators, and pin a `Val[T]`
See also
- The grammar rule it governs:
refined_type. - Every code in its category, Refinement, on the diagnostic index.
bynk explain bynk.refine.literal_violatesshows the same from the installed toolchain, without a network.