A match arm can list alternatives, A | B => .... The arm's body runs with the names the
pattern binds, whichever alternative matched, so every alternative must bind the same names,
each with the same type.
Wrong#
enum Shape { Circle(r: float), Square(side: float), Dot }
fn size(s: Shape): float = match s {
Circle(r) | Square(side) => r
Dot => 0.0
}Fixed#
enum Shape { Circle(r: float), Square(side: float), Dot }
fn size(s: Shape): float = match s {
Circle(x) | Square(x) => x
Dot => 0.0
}Common causes#
- Different names for the same field in two alternatives (
Circle(r) | Square(side)). - A name bound in one alternative only; use
_in all of them, or split the arm. - The same name bound to fields of different types.