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)wherex's type doesn't matcha's. - Struct-assignment field:
P { x, y } = pwhere 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.