Error codes

E0222: field access on an optional (use ?.)

In a terminal: auk explain E0222 prints this page.

On this page

The value is a T? and may be missing, so it has no fields of its own. Auk makes the missing case explicit: chain with ?. and give a fallback, or unwrap first.

Wrong#

auk
struct P { x: int }
fn get(p: P?): int = p.x

Fixed#

auk
struct P { x: int }
fn get(p: P?): int = p?.x else 0

Common causes#

  • A lookup (find, get, first) returns T?: use ?., ?, else or match.
  • x?.f works on T? only; for T! write (x?).f.

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