Error codes

E0029: struct literal or else in a control-flow head needs parentheses

In a terminal: auk explain E0029 prints this page.

On this page

In if, while, for and match heads, a { starts the body. A struct literal or an else there would be ambiguous, so Auk asks for parentheses around it.

Wrong#

auk
struct P { x: int }
fn origin(p: P): bool {
  if p == P { x: 0 } { true } else { false }
}

Fixed#

auk
struct P { x: int }
fn origin(p: P): bool {
  if p == (P { x: 0 }) { true } else { false }
}

Common causes#

  • Comparing with a struct literal in a condition.
  • while (x else 0) > 0 written without the parentheses around the else.
  • Binding the value to a let first is often clearer.

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