Skip to content
Playground(another site)

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 time

In the Book

See also

  • The grammar rule it governs: refined_type.
  • Every code in its category, Refinement, on the diagnostic index.
  • bynk explain bynk.refine.literal_violates shows the same from the installed toolchain, without a network.