Skip to content
TE124 · Type · error

`let … else` block must diverge

The `else` block can fall through. If it did, execution would continue into the pattern bindings using a value that did NOT match, so every path through `else` must return, panic, break or continue.

Why this fires

A let PATTERN = expr else { ... } block ran to completion without returning, panicking, breaking, or continuing. If the else block can fall through, execution would continue into the pattern's bindings using a value that did NOT match the pattern — so Zolo requires every path through else to diverge.

struct Point { x: int, y: int }

fn f(p) {
    let Point { x, .. } = p else { print("nope") }
    //                          ^^^^^^^^^^^^^^^^^^ error[TE124]: `else` block of
    //                          `let ... else` must diverge (return, panic, break, or continue)
    print(x)
}

Fix it

Make every path through the else block diverge:

fn f(p) -> int {
    let Point { x, .. } = p else { return 0 }   // ok
    return x
}
fn f(p) {
    let Point { x, .. } = p else { panic("not a point") }   // ok
    print(x)
}

See also

See also

Search Zolo

9 results

en