Skip to content
Playground(another site)

bynk.types.constructor_base_mismatch

Error A .of constructor was given an argument of the wrong base type.

Reps.of(x) checks a value of the type's base against its predicates, so x must already be that base: an Int for Reps. The constructor validates; it does not convert, so a String is refused before any predicate runs. Turn the value into the base first, such as with Int.parse, or take it as the base type. Reps.unsafe on an opaque type has the same rule.

Example

type Reps = Int where InRange(1, 100)
fn parse(s: String) -> Result[Reps, ValidationError] {
Reps.of(s) // ✗ `Reps.of` takes an `Int`
}
fn parse(n: Int) -> Result[Reps, ValidationError] {
Reps.of(n) // ✓
}

In the Book

See also

  • Every code in its category, Type checking, on the diagnostic index.
  • bynk explain bynk.types.constructor_base_mismatch shows the same from the installed toolchain, without a network.