T04

Error

Types

T04 — A value that may be null, read as if it were not

A field or method read from a value that may be null. if let, ??, ?. or a != null check narrows it.

What the compiler said

error[T04]: `user.email` may be null, so `.length` may fail --> src/App.wf:5:12 | 5 | Text("{user.email.length} characters") | ^^^^^^^^^^ = help: Unwrap it first: `if let x = value { … }`, `value ?? fallback`, `value?.field`, or a check for `!= null` = docs: https://webfluent.monzeromer.dev/errors/T04

Your editor offers this fix: Read it through null: ?.length. wf fix --code T04 applies it to every place it fits.

The fix

Broken

wf

type Member { name: String, email: String? } page P(path: "/", title: "T", description: "D") { state user = Member(name: "Ada", email: null) Heading("Profile").h1 Text("{user.email.length} characters") }

Fixed

wf

type Member { name: String, email: String? } page P(path: "/", title: "T", description: "D") { state user = Member(name: "Ada", email: null) Heading("Profile").h1 Text("{user.email?.length ?? 0} characters") }

Unwrap it: if let e = user.email { e.length }, user.email?.length ?? 0, or (user.email ?? "").length. Your editor's quick fix, and wf fix --code T04, write the ?. for you.

Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).

lints cannot lower it: it would ship a broken page.