Error codes

E0205: if without else used as a value

In a terminal: auk explain E0205 prints this page.

On this page

if is an expression, but without an else it has no value when the condition is false. When its value is used, every path must produce one.

Wrong#

auk
fn sign(c: bool): int = if c { 1 }

Fixed#

auk
fn sign(c: bool): int = if c { 1 } else { 0 }

Common causes#

  • A missing else branch in a function's final expression.
  • An if as the last line of a block whose value is returned.
  • To run code only sometimes, put the if before the block's real result.

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