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#
fn count(m: {str: int}, k: str): int = m.get(k) ?? 0Fixed#
fn count(m: {str: int}, k: str): int = m.get(k) else 0Common causes#
- Habit from C#, Swift, Kotlin or JavaScript, where
x ?? dis the default operator. - Writing
x ?? dinside arithmetic: write(x else d) + 1.