Error codes

E0039: ?? used as a default operator (use else)

In a terminal: auk explain E0039 prints this page.

On this page

In Auk ?? is a hole (a placeholder the compiler describes for you) or two postfix ? in a row. It is not a null-coalescing operator: a default for a missing (T?) or failed (T!) value is written with else. else binds loosest, so inside a larger expression it needs parentheses: (m.get(k) else 0) + 1.

Wrong#

auk
fn count(m: {str: int}, k: str): int = m.get(k) ?? 0

Fixed#

auk
fn count(m: {str: int}, k: str): int = m.get(k) else 0

Common causes#

  • Habit from C#, Swift, Kotlin or JavaScript, where x ?? d is the default operator.
  • Writing x ?? d inside arithmetic: write (x else d) + 1.

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