Skip to content
TE123 · Type · error

No such field in destructuring pattern

A destructuring pattern — `let Struct { … } = expr`, an anonymous `let { … }`, a parameter pattern, or a struct-destructuring assignment — names a field the struct doesn't have.

Why this fires

A destructuring pattern (let Struct { ... } = expr, an anonymous let { ... } = expr, a parameter pattern, or a struct-destructuring assignment Struct { ... } = expr) names a field that doesn't exist on the struct being destructured.

struct User { name: str, age: int }

fn f(u: User) {
    let { nmae } = u
    //     ^^^^ error[TE123]: no field 'nmae' on the scrutinee in pattern. Did you mean 'name'?
    print(nmae)
}

It also fires in parameter position, this time naming the struct explicitly:

struct Point { x: int, y: int }

fn f(Point { z }) { print(z) }
//          ^ error[TE123]: struct 'Point' has no field 'z' in pattern. Did you mean 'x'?

Fix it

Fix the field name to match the struct's real fields:

fn f(u: User) {
    let { name } = u          // ok
    print(name)
}

See also

  • TE102 — the same "unknown field" check for a plain .field access.
  • TE126 — anonymous pattern needs an inferable struct type.
  • /docs/pattern-matching — struct destructuring patterns.

See also

Search Zolo

9 results

en