Skip to content
Playground(another site)

bynk.parse.lambda_pattern_refutable

Error A lambda parameter's record pattern can fail to match some value of its type, and a lambda has no else to fall back on.

A lambda parameter pattern must match every value of its type, because a lambda has no else for the rest. Item { status: Paid, qty, .. } matches only some items. Use bare names, f: name or f: _; the note names the first field that can fail. To handle the other cases, take a name and match on it in the body.

Example

items.map((Item { status: Paid, qty, .. }) => qty) // ✗ not every item is `Paid`
items.map((i) => match i.status { // ✓ every status is handled
Paid => i.qty
Pending => 0
})

In the Book

See also

  • The grammar rule it governs: lambda_param.
  • Every code in its category, Parser, on the diagnostic index.
  • bynk explain bynk.parse.lambda_pattern_refutable shows the same from the installed toolchain, without a network.