Error codes

E0267: the alternatives of an or-pattern bind different names or types

In a terminal: auk explain E0267 prints this page.

On this page

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#

auk
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#

auk
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.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page