tripon[github]

diagnostic codes / Types

E0204 no-null

`null` was written, and there is no `null`.

E0204no-nullnull and undefined do not exist; use opt<T>
severityerror
bandTypes
in the v0 bootstrapemitted
explainralt explain E0204

`null` and `undefined` are not values, not keywords with no meaning, not anything. The name-resolution pass recognises both spellings and reports this code with the replacement in the message. A missing value is represented by `opt<T>`, and it cannot be used without a `match` or a `?`.

What it looks like

e0204.tp
use tier core;

fn main() -> i32 {
    let o: opt<i32> = null;
    return 0;
}
ralt check e0204.tp
e0204.tp:4:23: error: null and undefined do not exist; use opt (T) for may-be-missing values
  [E0204 no-null] null and undefined do not exist; use opt<T>

The human message renders the angle brackets as `opt (T)`; the hint line prints `opt<T>`. Both are the compiler's text; they are reproduced here rather than normalised.

What to do

  • Use `opt<T>` and construct it with `some(v)` or `none`.
  • Unwrap it with `match`, or propagate it with `?` from a function returning `opt<T>`.
  • For a failure with a reason, use `result<T, E>` instead.

Why the code exists

A null that can appear anywhere is a null that must be checked everywhere. Removing the value removes the check from every type that does not opt in.

What ralt explain says

ralt explain E0204
E0204
severity: error
name: no-null
hint: null and undefined do not exist; use opt<T>

Related