Skip to content
Playground(another site)

bynk.types.variant_arity

Error A variant constructor got the wrong number of arguments for its payload fields (a pattern with the wrong number of bindings is bynk.types.pattern_arity).

A variant is built like a call, with one argument for each payload field it declares, so Circle(radius: Int) takes one and a variant with no payload is written bare. A different number of arguments is refused at the construction. Pass one value for each declared field, or change the type declaration if the variant should carry more. The same code covers the built-in QueueResult and HttpResult constructors. A match arm with the wrong number of bindings is the separate code bynk.types.pattern_arity.

Example

type Shape =
| Circle(radius: Int)
| Square(side: Int)
fn make() -> Shape {
Circle(1, 2) // ✗ `Circle` takes 1 argument
}
fn make() -> Shape {
Circle(1) // ✓
}

In the Book

See also

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