Skip to content
Playground(another site)

bynk.types.mixed_pattern_bindings

Error A pattern mixes named and positional bindings.

A variant pattern binds its payload either by field name, Circle(r: x, d: y), or by position, Circle(x, y). Mixing the two leaves it unclear which field a bare name takes, so Bynk wants one style in each pattern. Name every field, or none.

Example

type Shape = | Circle(r: Int, d: Int) | Dot
fn size(s: Shape) -> Int {
match s {
Circle(r: x, y) => x // ✗ one named binding, one positional
Dot => 0
}
}
fn size(s: Shape) -> Int {
match s {
Circle(x, y) => x // ✓ all positional
Dot => 0
}
}

In the Book

See also

  • The grammar rule it governs: variant_pattern.
  • Every code in its category, Type checking, on the diagnostic index.
  • bynk explain bynk.types.mixed_pattern_bindings shows the same from the installed toolchain, without a network.