Saltar al contenido
TE129 · Tipos · error

Cantidad de valores incompatible en la asignación de tupla

Una asignación con destructuring de tupla (`(a, b, c) = expr`) tiene un número de destinos distinto al número de valores de `expr`.

Why this fires

A tuple-destructuring assignment ((a, b, c) = expr) has a different number of targets than expr has values.

fn pair() -> (int, int) { return (1, 2) }

fn f() {
    var a = 1
    var b = 2
    var c = 3
    (a, b, c) = pair()
    //          ^^^^^^ error[TE129]: tuple assignment expects 3 values, got 2
}

Fix it

Match the target count to the value count:

fn f() {
    var a = 1
    var b = 2
    (a, b) = pair()          // ok — 2 targets for a 2-tuple
}

Use _ to discard a value you don't need without changing the count:

fn f() {
    var a = 0
    (a, _) = pair()          // ok — discards the second value
    print(a)
}

See also

  • TE005 — a type mismatch in one tuple-assignment slot.
  • TE130 — destructuring assignment only supports =.
  • /docs/pattern-matching — destructuring assignment.

Véase también

Buscar en Zolo

9 resultados

en