Saltar al contenido
TE123 · Tipos · error

Campo inexistente en el patrón de destructuring

Un patrón de destructuring — `let Struct { … } = expr`, un `let { … }` anónimo, un patrón de parámetro o una asignación con destructuring de struct — nombra un campo que el struct no tiene.

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.

Véase también

Buscar en Zolo

9 resultados

en