Skip to content
ZOLO / TE005 Type · error

type mismatch in tuple-assignment slot

Operators like `+=`, `-=`, `*=` require both sides to be numeric (or strings for `+=`).

Why this fires

A type mismatch was found in one slot of a tuple-destructuring assignment, in one field of a struct-destructuring assignment, or on the target of a compound assignment (+=, -=, *=, /=, //=, %=). Concrete shapes:

  • Tuple-assignment slot: (a, b) = (x, y) where x's type doesn't match a's.
  • Struct-assignment field: P { x, y } = p where a field's type doesn't match the target variable's.
  • Compound assignment: the target isn't numeric (or str, for +=).
fn f() {
    var a = 1
    var b = "two"
    (a, b) = (10, 20)
    //        ^^^^^^^ error[TE005]: cannot assign `int` to `str` in tuple assignment slot 2
}
fn f() {
    var name = "hi"
    name -= 1
    //   ^^^^^ error[TE005]: compound assignment requires numeric type, found str
}

Fix it

1. Match the tuple/struct slot's type

fn f() {
    var a = 1
    var b = 0
    (a, b) = (10, 20)      // ok — both slots are int
}

2. Only use compound assignment on numeric (or string, for +=) targets

var count = 0
count += 1                 // ok — int += int

var name = "hi"
name = name + "!"          // use plain `+` for string concatenation, not `-=`/`*=`/etc.

See also

  • TE004 — the same check for a plain (non-destructuring) assignment.
  • TE129 — tuple-assignment value-count mismatch (arity, not type).
  • TE130 — destructuring assignment only supports =.

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br